Different stdout
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Different stdout




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Different stdout  
kenkahn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-12-06 07: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.






[ Post a follow-up to this message ]



    Re: Different stdout  
David Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-12-06 07: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







[ Post a follow-up to this message ]



    Re: Different stdout  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-12-06 07: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.





[ Post a follow-up to this message ]



    Re: Different stdout  
kenkahn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-13-06 12:51 PM

>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 be
tween >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.






[ Post a follow-up to this message ]



    Re: Different stdout  
Pascal Bourguignon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-13-06 10: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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:55 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register