Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ruben Safir <mrbrklyn@panix.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | forking madness |
| Date | 2015-03-02 23:41 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <md2sfm$f67$1@reader1.panix.com> (permalink) |
Anyone know why this might not fuction as I thought it might. It seems
to start at the beginning of main when a process is forked
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main( int argc, char * argv[]){
pid_t pid;
pid_t pid_ret;
int i = 0;
printf("\n___Before the While Loop where Loop is ==> %d__", i);
while( i++ < 100){
puts("\nBefore the Fork in the Loop:");
printf( "Loop ==> %d \n", i);
pid = fork();
printf("\nFork: This should print twice for every loop:
%d", i);
if(pid < 0){
puts( "fork failed\n" );
return 1;
}
if(pid == 0) {
puts("\n\nChildren of the world unite");
printf("Am Yisrael Chai! pid =>%d \n", pid);
printf( "Loop in Child ==> %d \n", i);
puts("BYE!!");
exit( EXIT_SUCCESS );
}
if (pid > 0 ){
printf("\nIn the Parent => I'm waiting %d\n", pid );
printf( "Loop in Parent ==> %d \n", i);
pid_ret = wait(NULL);
puts("Done Waiting for Child");
printf("\nProcess that returned was ==> %d", pid_ret );
printf("\n*******************************\n" );
}
}
return 0;
}
~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
___Before the While Loop where Loop is ==> 0__
Before the Fork in the Loop:
Loop ==> 1
Fork: This should print twice for every loop: 1
Children of the world unite
Am Yisrael Chai! pid =>0
Loop in Child ==> 1
BYE!!
___Before the While Loop where Loop is ==> 0__
Before the Fork in the Loop:
Loop ==> 1
Fork: This should print twice for every loop: 1
In the Parent => I'm waiting 29294
Loop in Parent ==> 1
Done Waiting for Child
Process that returned was ==> 29294
*******************************
Before the Fork in the Loop:
Loop ==> 2
Fork: This should print twice for every loop: 2
Children of the world unite
Am Yisrael Chai! pid =>0
Loop in Child ==> 2
BYE!!
___Before the While Loop where Loop is ==> 0__
Before the Fork in the Loop:
Loop ==> 1
Fork: This should print twice for every loop: 1
In the Parent => I'm waiting 29294
Loop in Parent ==> 1
Done Waiting for Child
Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread
forking madness Ruben Safir <mrbrklyn@panix.com> - 2015-03-02 23:41 +0000
Re: forking madness Keith Thompson <kst-u@mib.org> - 2015-03-02 16:05 -0800
Re: forking madness fir <profesor.fir@gmail.com> - 2015-03-03 01:20 -0800
Re: forking madness Noob <root@127.0.0.1> - 2015-03-03 15:50 +0100
Re: forking madness fir <profesor.fir@gmail.com> - 2015-03-03 07:57 -0800
Re: forking madness Nobody <nobody@nowhere.invalid> - 2015-03-07 07:07 +0000
Re: forking madness fir <profesor.fir@gmail.com> - 2015-03-07 05:05 -0800
Re: forking madness Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-02 19:25 -0500
Re: forking madness Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-02 19:32 -0500
Re: forking madness ruben <nowhere@nowhere.nor> - 2015-03-03 14:56 +0000
Re: forking madness Keith Thompson <kst-u@mib.org> - 2015-03-03 07:54 -0800
Re: forking madness asetofsymbols@gmail.com - 2015-03-05 00:03 -0800
Re: forking madness asetofsymbols@gmail.com - 2015-03-05 00:21 -0800
Re: forking madness asetofsymbols@gmail.com - 2015-03-05 00:44 -0800
Re: forking madness Lőrinczy Zsigmond <nospam@for.me> - 2015-03-03 17:45 +0100
Re: forking madness Keith Thompson <kst-u@mib.org> - 2015-03-03 09:44 -0800
Re: forking madness Lőrinczy Zsigmond <nospam@for.me> - 2015-03-03 19:06 +0100
Re: forking madness James Kuyper <jameskuyper@verizon.net> - 2015-03-03 13:57 -0500
Re: forking madness Lőrinczy Zsigmond <nospam@for.me> - 2015-03-04 06:53 +0100
Re: forking madness Chad <cdalten@gmail.com> - 2015-03-05 14:09 -0800
csiph-web