📄 ttys_time.c
字号:
#include "cmd.h"#include "tty.h"#include "ctrl.h"#include <sys/poll.h>#include <sys/time.h>#include <time.h>char cmd = RV;int fd;char rbuf[4];int main() { struct timeval tv, tvo; double t; // init ttys fd = ttys_init(0); // init ctrl ctrl_init(fd); gettimeofday(&tvo, NULL); if (write(fd, &cmd, 1) != 1) { fprintf(stderr, "write error\n"); return -1; } struct pollfd ufds = {fd, POLLIN}; int n; int i = 0; for (; i<300; ++i) { if (poll(&ufds, 1, -1) <= 0) { fprintf(stderr, "poll error\n"); return -1; } if ((n = read(fd, rbuf, sizeof(rbuf))) <= 0) { fprintf(stderr, "read error\n"); return -1; } gettimeofday(&tv, NULL); t = tv.tv_sec - tvo.tv_sec; t += (double)(tv.tv_usec - tvo.tv_usec) / 1e6; tvo = tv; printf("%d\t%f\n", n, t); if (write(fd, &cmd, 1) != 1) { fprintf(stderr, "write error\n"); return -1; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -