📄 child.cpp
字号:
#include <cstdio>#include <sys/stat.h>#include <cerrno>#include <fcntl.h>#include <unistd.h>#include <iostream>#include <stdlib.h>using namespace std;int main(int argc, char *argv[]){ int fd; int n; const char*mark = "This is child process write."; char buf[50]; if (argc != 2) { cout << "Usage: child <filename> " << endl; exit(0); } fd = atoi(argv[1]); if(fd < 0) { perror("file descriptor error"); exit(1); } n = write(fd,mark, strlen(mark)); if (n == -1) { perror("child write mark error"); exit(1); } lseek(fd,0,SEEK_SET); n = read(fd, buf, sizeof(buf)); if (n == -1) { perror("read error"); exit(1); } buf[n]='\0'; cout << "Read the message is: "<< buf << endl; close(fd); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -