C
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- takezoh
- まろ
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- @tyottyoworks
- ___shanon
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
33
1
2
3
4
5
6
7
int main() {
8
int fd[2] , ret = 0;
9
char buffer[] = "Marvellous InfoSystems";
10
char readBuff[BUFSIZ] = "01234567890123456789012345678901234567890";
11
pid_t Childpid;
12
13
pipe(fd); //create a oneway communication channel i.e pipe i.e unnamed pipe
14
15
Childpid = fork();
16
17
if(Childpid == 0) //child process
18
{
19
close(fd[0]); /*close the ipnut side of the pipe after entering the child process*/
20
printf("Child intiaites communication by writing the data at output side of the pipe \n");
21
write(fd[1] , buffer , sizeof(buffer)); /*Child process writes at the output side of the pipe*/
22
}
23
else //parent process
24
{
25
close(fd[1]); /*Close output side of the pipe after the entering the parent proces*/
26
ret = read(fd[0] , readBuff , sizeof(readBuff));/*Parent proces reads the data i.e written by the child at output side of the
27
pipe*/
28
printf("The data read by Parent process is : %s \n",readBuff);
29
}
30
31
return 0;
32
}
33
$ gcc prog.c -Wall -Wextra -std=c99
Start
prog.c: In function 'main': prog.c:8:18: warning: variable 'ret' set but not used [-Wunused-but-set-variable] 8 | int fd[2] , ret = 0; | ^~~
Child intiaites communication by writing the data at output side of the pipe The data read by Parent process is : Marvellous InfoSystems
0
Finish