?? 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 + -