📄 jerry.c
字号:
/* jerry.c v2.0 */#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/wait.h>#include <fcntl.h>#include <stdlib.h>#include <stdio.h>#define FILE "message.txt"#define CHILD_MSG "I am Mickey.\n"#define FATHER_MSG "I am Jerry.\n"int main(){ int fd; char buf[BUFSIZ]; ssize_t s; /* Open file for read. */ fd = open(FILE, O_RDONLY, 0666); if(fd < 0) { perror("open"); } /* Read message. */ do { s = read(fd, &buf, BUFSIZ); write(STDOUT_FILENO, &buf, s); } while (s>0); /* Close file. */ close(fd); if(fork() == 0) { write(STDOUT_FILENO, CHILD_MSG, sizeof(CHILD_MSG)-1); } else { wait(NULL); /* wait for any child exit. */ write(STDOUT_FILENO, FATHER_MSG, sizeof(FATHER_MSG)-1); } exit(EXIT_SUCCESS);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -