Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | ruben <nowhere@nowhere.nor> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: forking madness |
| Date | 2015-03-03 14:56 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <md4i2r$gt6$2@reader1.panix.com> (permalink) |
| References | <md2sfm$f67$1@reader1.panix.com> <hc7Jw.139572$Oy4.112794@fx17.iad> |
On Mon, 02 Mar 2015 19:25:48 -0500, Lew Pitcher wrote:
> Having said that, take a look at your program. Specifically, the line
> that reads
> printf("\n___Before the While Loop where Loop is ==> %d__", i);
>
> Note that, at this point in your code, if you are outputing to a
> line-buffered device (such as a console), you /have not/ written the
> string out. The next newline (or a call to fflush() ) will flush the
> buffer, and cause the string to write out. Such is the way of buffered
> I/O.
>
> So, prior to the fork(), you have a buffer that contains a string, not
> written to stdout.
wow - that completely normalized the code. Prior to that I was getting
almost a recursion affect by parent which was going to be my next
question. Now i still have the question but it is a slightly different
question.
Without the fflush the parent kept rewriting to stdout the whole loop
over and over again as what is posted here
http://www.nylxs.com/docs/grad_school/operating_systems/output.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and so on...
Is the buffer being recopied in the parent on every fork?
___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
Process that returned was ==> 29294
*******************************
Before the Fork in the Loop:
Loop ==> 2
Fork: This should print twice for every loop: 2
In the Parent => I'm waiting 29295
Loop in Parent ==> 2
Done Waiting for Child
Process that returned was ==> 29295
*******************************
Before the Fork in the Loop:
Loop ==> 3
Fork: This should print twice for every loop: 3
Children of the world unite
Am Yisrael Chai! pid =>0
Loop in Child ==> 3
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
In the Parent => I'm waiting 29295
Loop in Parent ==> 2
Done Waiting for Child
Process that returned was ==> 29295
*******************************
Before the Fork in the Loop:
Loop ==> 3
Fork: This should print twice for every loop: 3
In the Parent => I'm waiting 29296
Loop in Parent ==> 3
Done Waiting for Child
Process that returned was ==> 29296
*******************************
Before the Fork in the Loop:
Loop ==> 4
Fork: This should print twice for every loop: 4
Children of the world unite
Am Yisrael Chai! pid =>0
Loop in Child ==> 4
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
In the Parent => I'm waiting 29295
Loop in Parent ==> 2
Done Waiting for Child
Process that returned was ==> 29295
*******************************
Before the Fork in the Loop:
Loop ==> 3
Fork: This should print twice for every loop: 3
In the Parent => I'm waiting 29296
Loop in Parent ==> 3
Done Waiting for Child
Process that returned was ==> 29296
*******************************
Before the Fork in the Loop:
Loop ==> 4
Fork: This should print twice for every loop: 4
In the Parent => I'm waiting 29297
Loop in Parent ==> 4
Done Waiting for Child
Process that returned was ==> 29297
*******************************
Before the Fork in the Loop:
Loop ==> 5
Fork: This should print twice for every loop: 5
Children of the world unite
Am Yisrael Chai! pid =>0
Loop in Child ==> 5
BYE!!
Back to comp.lang.c | Previous | Next — Previous in thread | 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