Click here to Skip to main content
15,905,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

i m in the start of C, Linux ... may u help me please how can i create 4 Process and Piping a message in c Linux?

process1 give the result by pipe1 to process2 ... process 2 by pipe2 send the result to process3 then process3 give the result to process4 by pipe3 and process4 save the result into a file..

wait for ur kind answers...
many thanks
-lida
Posted
Comments
Sergey Alexandrovich Kryukov 2-Dec-12 1:02am    
You range is amazing. Now, didn't you expect traditional question: what did you try?
--SA
AmitGajjar 2-Dec-12 1:41am    
at least you should respect when someone helping you without any expectation. what will you loss if you reply him nicely ?
lida zar 2-Dec-12 1:52am    
i did ... but he again and again discuss with me about own myself ... when i tried very much on google and etc ... how can i solve it lonely ... and also sergey make me upset ... instead of help me to solve my problem ... only review my questions and my knowledge ... yes my knowledge isn't good like him or other one which manage here ... im only a simple student and trying to stand on my own ... then i really don't know why he do joking with me ( a girl) ?
AmitGajjar 2-Dec-12 2:31am    
it's not like that. when your parents punish they are not doing joking with you, they actually try to teach you something. SA want you to learn yourself. everyone phase the same student life. but if you will not try something yourself, you always need someone's help.

But one golden rule to learn is "never get upset when you fail in your work"

best luck.
lida zar 2-Dec-12 2:40am    
ok thanks anyways ... i surrender!

 
Share this answer
 
Its for only 3 processes :-
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

#define MSGSIZE    14 
 
char *message = "hello, world!"; 
 
 
main() { 
char inbuf[MSGSIZE];
int p[3];

pid_t pid;
pid_t pid1;
 
if (pipe(p) == -1){ 
perror("pipe call"); 
exit(1); 
 
}


pid = fork();
pid1 = fork();


if(pid == -1){

perror("Fork failed");
exit(1);

}

if(pid | pid1 == 0)//process A
{
    close(p[0]); 
    write(p[1], message, MSGSIZE);
    read(p[1], message, MSGSIZE);
    write(p[2], message, MSGSIZE);
    
}

/*else if(pid1 == 0){

    close(p[1]);
    //read(p[1], message, MSGSIZE);
    write(p[2], message, MSGSIZE);
    
}*/


else{
    //parent process C
    close(p[2]); 
    read(p[0], inbuf, MSGSIZE);
    printf("Pipelined message return:%s\n", inbuf);
    wait(NULL); 
}

exit(0);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900