Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Linux
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 1-Dec-12 18:54pm
Comments
Sergey Alexandrovich Kryukov at 2-Dec-12 1:02am
   
You range is amazing. Now, didn't you expect traditional question: what did you try?
--SA
@AmitGajjar at 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 at 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 at 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 at 2-Dec-12 2:40am
   
ok thanks anyways ... i surrender!
@AmitGajjar at 2-Dec-12 6:42am
   
its good to see you understand at this level.
lida zar at 2-Dec-12 6:47am
   
my IQ is working now :)) thanks ..
Sergey Alexandrovich Kryukov at 2-Dec-12 14:00pm
   
Don't surrender and don't get upset. Just realize that I give you a good advice.
Now, I know you are a girl, but what's wrong with joking with you? I call it sexism. We all have equal rights and should be treated equally, OK? Let's not go wrong way...
--SA
lida zar at 2-Dec-12 14:59pm
   
ok
Sergey Alexandrovich Kryukov at 2-Dec-12 20:02pm
   
!
Sergey Alexandrovich Kryukov at 2-Dec-12 13:56pm
   
Golden words, Amit!
--SA
@AmitGajjar at 2-Dec-12 22:57pm
   
thank you.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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);
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 280
1 Sergey Alexandrovich Kryukov 279
2 CPallini 205
3 Maciej Los 197
4 Afzaal Ahmad Zeeshan 160
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 2 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100