Unix Programming - Different stdout

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2006 > Different stdout





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Different stdout
kenkahn

2006-03-12, 2:47 am

Is there anyway to start a child process (via fork() I assume) that
does not share it's stdout with the parent process? I need to buffer
the stdout of a child process (setvbuf) but not of the parent proces
that spawns it.

David Schwartz

2006-03-12, 2:47 am


"kenkahn" <kenkahn@optonline.net> wrote in message
news:1142131874.878148.196580@i40g2000cwc.googlegroups.com...

> Is there anyway to start a child process (via fork() I assume) that
> does not share it's stdout with the parent process?


Certainly, just change stdout after the call to 'fork' in just the
child.

> I need to buffer
> the stdout of a child process (setvbuf) but not of the parent proces
> that spawns it.


You can't use stdio in both the parent and the child unless you call
'exec'. If you call 'exec', there is no 'I' any more.

DS


Paul Pluzhnikov

2006-03-12, 2:47 am

"David Schwartz" <davids@webmaster.com> writes:

> You can't use stdio in both the parent and the child unless you call
> 'exec'.


Why not?
[Just do "flush(NULL);" before the fork()].

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
kenkahn

2006-03-13, 7:51 am

>Certainly, just change stdout after the call to 'fork' in just the child.

But won't that also change the stdout of the parent process? My
understanding is that file handle You can't use stdio in both the
parent and the child unless you call

>'exec'. If you call 'exec', there is no 'I' any more. s are inherited and shared between >parent/child.


But if I'm understanding this correctly, exec also doesn't return if
the call is successful; I need both parent and child to be running.

I guess I could just start a new process via system() or such, but I
wanted for the child to automatically end if the parent ended. I also
guess I could use some sort of IPC to kill the child if the parent
ends, but I was hoping for something simplier.

Pascal Bourguignon

2006-03-13, 5:54 pm

"kenkahn" <kenkahn@optonline.net> writes:

>
> But won't that also change the stdout of the parent process? My
> understanding is that file handle You can't use stdio in both the
> parent and the child unless you call


Each process has its own set of file descriptors. If you change the
file descriptor in the children, it cannot have an effect on the
parent or on any other process.


>
> But if I'm understanding this correctly, exec also doesn't return if
> the call is successful; I need both parent and child to be running.
>
> I guess I could just start a new process via system() or such, but I
> wanted for the child to automatically end if the parent ended. I also
> guess I could use some sort of IPC to kill the child if the parent
> ends, but I was hoping for something simplier.


This is done by keeping the child in the same process group as the parent.

--
__Pascal Bourguignon__ http://www.informatimago.com/
Un chat errant
se soulage
dans le jardin d'hiver
Shiki
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com