Example: #include #include #include #include #include #include #include #define ERROR -1 void main() { int fd; int freecon; if ((fd = open("/dev/console", O_NOCTTY)) == ERROR) { perror("open"); exit(ERROR); } printf("w00w00!\n\n"); if (ioctl(fd, VT_OPENQRY, &freecon) == ERROR) { perror("ioctl"); close(fd); exit(ERROR); } printf("The first free (non opened) console is tty%d\n", freecon); close(fd); }