Results 1 to 4 of 4
hello, first post here.. to be honest:
I fail as a programmer, etc etc, I'm a n00b etc etc..
I've to solve a problem by using pipes.
client gives server ...
- 11-05-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 2
C pipes, forks -- it doesn't works
hello, first post here.. to be honest:
I fail as a programmer, etc etc, I'm a n00b etc etc..
I've to solve a problem by using pipes.
client gives server a username, server gives back.. well for us, the command which the client can use to view how many processes the user has open.
get ready for something ugly. and not working.
tell me everything I need to know, and point out all that I've done wrong, thanks.
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> int pid, client[2], serv[2]; char buf1[128], buf2[128]; int main (int argc, char **argv) { if ((argc == 1) || (argc > 2)) { printf ("\nspecify user.\n"); exit(1); } else { pipe (serv); pid = fork(); pipe (client); if (!pid) { close (client[1]); write (serv[1], argv[1], strlen(argv[1])); read (client[0], buf1, strlen(buf1)); popen (buf1, "w"); exit (0); } if (pid > 0) { // char temp[128]; close (serv[1]); read (serv[0], buf1, strlen(buf1)); sprintf (buf2, "ps -u %s", buf1); write (client[1], buf2, strlen(buf2)); wait (NULL); } if (pid < 0) { perror ("fork"); } } return 0; }
- 11-05-2008 #2
I didn't go over the whole thing with a fine tooth comb, but to begin with, you want to do both pipe()s before you do the fork().
--
Bill
Old age and treachery will overcome youth and skill.
- 11-05-2008 #3Just Joined!
- Join Date
- Nov 2008
- Posts
- 2
is this the entire source?
if it is, you have not included unistd.h // for pipes and fork
- 11-05-2008 #4Just Joined!
- Join Date
- Oct 2008
- Posts
- 2


Reply With Quote
