范例:
#include<unistd.h>
#include<sys/types.h>
#include <sys/stat.h>
#include<fcntl.h>
main()
{
int fd;
char * file = “/dev/tty”;
fd = open (fiel,O_RDONLY);
printf(“%s”,file);
if(isatty(fd)){
printf(“is a tty.\n”);
printf(“ttyname = %s \n”,ttyname(fd));
}
else printf(“ is not a tty\n”);
close(fd);
}
执行 /dev/tty is a tty
ttyname = /dev/tty |