#include #include #include #include #include #include #include #define BSIZE 512 void *kill_task(void *arg) { kill(getpid(), SIGINT); return NULL; } int io_task(const char *fname, off_t size) { int fd; int res; char buf[BSIZE]; int n = 0; pthread_t tid; while (1) { fd = open(fname, O_RDONLY); if (fd < 0) { perror("faild to open file:"); return fd; } res = lseek(fd, random() % size, SEEK_SET); if (res < 0) { perror("stat"); return res; } if (n) { /* try to simulate system call interrupt */ pthread_create(&tid, NULL, kill_task, NULL); } read(fd, buf, BSIZE); pthread_yield(); res = close(fd); if (res < 0) { perror("faild to close file:"); return res; } n++; } return 0; } int main(int argc, char *argv[]) { struct stat sbuf; const char *fname; if (argc != 2) { printf("Usage: %s: \n", argv[0]); exit(1); } fname = argv[1]; if (stat(fname, &sbuf) < 0) { perror("stat"); exit(1); } io_task((void *) fname, sbuf.st_size); return 0; }