cat
shuai@ubuntu:~/Desktop$ cat sun.c -n|head -10|tail -5
shuai@ubuntu:~/Desktop$ cat sun.c -n
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <zconf.h>
4 #include <cstring>
5
6 int main() {
7
8 // 創(chuàng)建無名管道
9 int fd[2];
10 if (pipe(fd) == -1)
11 exit(1);
12
13 // 管道傳遞信息
14 char msgSend[] = "我在寫呢";
15 char msgRecv[32];
16
17 int pid = fork();
18
19 if (pid == 0) {
20 // 子進(jìn)程
21 close(fd[1]); // 關(guān)閉管道寫入端秧饮,準(zhǔn)備讀
22 printf("before read data from pipe!\n");
23 read(fd[0], msgRecv, strlen(msgSend)); // 把信息讀入msgRecv
24 printf("read [%s] from pipe\n", msgRecv);
25 } else {
26 // 父進(jìn)程
27 close(fd[0]); // 關(guān)閉管道讀取端映挂,準(zhǔn)備寫
28 printf("Parent sleeping ......\n");
29 sleep(3); // 迫使子進(jìn)程先執(zhí)行
30 printf("Parent wake up !\n");
31 write(fd[1], msgSend, strlen(msgSend));
32 wait(0);
33 }
34 exit(0);
35 }
shuai@ubuntu:~/Desktop$ cat sun.c -n|head -10|tail -5
6 int main() {
7
8 // 創(chuàng)建無名管道
9 int fd[2];
10 if (pipe(fd) == -1)
sed
shuai@ubuntu:~/Desktop$ sed -n '6,10p' sun.c|cat -n
1 int main() {
2
3 // 創(chuàng)建無名管道
4 int fd[2];
5 if (pipe(fd) == -1)
shuai@ubuntu:~/Desktop$
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者