ioctl
跳转到导航
跳转到搜索
tty
获取当前 tty 号[1]。使用的文件描述符是当前 tty 或者 /dev/console
(需要 root 权限):
#include<sys/ioctl.h>
#include<linux/vt.h>
#include<stdio.h>
/* --------------------------------------------------------------------- */
int main(int argc, char **argv){
struct vt_stat buf = {0};
if(ioctl(1, VT_GETSTATE, &buf)){
perror("ioctl");
}
printf("%hu %hu %hu\n", buf.v_active, buf.v_signal, buf.v_state);
return 0;
}
buf.v_active
即是当前 tty 号。
参考资料
- ↑ man console_ioctl(4)