linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* a 'wrapper'
@ 2002-06-29 10:25 xlp
  2002-06-29 14:49 ` Jan-Benedict Glaw
  0 siblings, 1 reply; 3+ messages in thread
From: xlp @ 2002-06-29 10:25 UTC (permalink / raw)
  To: linux-c-programming

hi, i have been trying to let certain process working on a remote machine in this way:
nohup ./a.out >> /dev/null &
but when i log off, the process dies.
Can i code a certain process that fork itself, call setsid() and run a.out with system() or exec() ?
How can i deal with this situation? I want that the executable object a.out forget about terminal control and do its work without care about sdtin/stdout/stderr.

bye Unix friends.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: a 'wrapper'
  2002-06-29 10:25 a 'wrapper' xlp
@ 2002-06-29 14:49 ` Jan-Benedict Glaw
  2002-06-30  7:52   ` Ben Marsh
  0 siblings, 1 reply; 3+ messages in thread
From: Jan-Benedict Glaw @ 2002-06-29 14:49 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]

On Sat, 2002-06-29 05:25:02 -0500, xlp <xlp@emtel.net.co>
wrote in message <20020629052348.A50622@nietzsche>:
> hi, i have been trying to let certain process working on a remote machine in this way:
> nohup ./a.out >> /dev/null &
> but when i log off, the process dies.
> Can i code a certain process that fork itself, call setsid() and run a.out with system() or exec() ?
> How can i deal with this situation? I want that the executable object a.out forget about terminal control and do its work without care about sdtin/stdout/stderr.

You should never ever use system(), is's insecure. Use exec*(). However,
you won't need that - try this:

	nohup ./a.out > /dev/null 2>&1 < /dev/null &

It probably dies because of a SIGPIPE if it attempts to read something
from stdin or if it tries to write to stdout. You break this file
descriptors in the moment you log off...

MfG, JBG

-- 
Jan-Benedict Glaw   .   jbglaw@lug-owl.de   .   +49-172-7608481
	 -- New APT-Proxy written in shell script --
	   http://lug-owl.de/~jbglaw/software/ap2/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: a 'wrapper'
  2002-06-29 14:49 ` Jan-Benedict Glaw
@ 2002-06-30  7:52   ` Ben Marsh
  0 siblings, 0 replies; 3+ messages in thread
From: Ben Marsh @ 2002-06-30  7:52 UTC (permalink / raw)
  To: linux-c-programming

<I have jumped in part way through since I just subscribed.>

On Sunday, June 30, 2002, at 12:49 AM, Jan-Benedict Glaw wrote:

> On Sat, 2002-06-29 05:25:02 -0500, xlp <xlp@emtel.net.co>
> wrote in message <20020629052348.A50622@nietzsche>:
>> hi, i have been trying to let certain process working on a remote 
>> machine in this way:
>> nohup ./a.out >> /dev/null &
>> but when i log off, the process dies.
>> Can i code a certain process that fork itself, call setsid() and run 
>> a.out with system() or exec() ?
>> How can i deal with this situation? I want that the executable object 
>> a.out forget about terminal control and do its work without care about 
>> sdtin/stdout/stderr.

As I understand it you can leave a process running on another machine 
after you disconnect by using nohup(1).  I can only assume that it 
didn't work because you try and take stdout and append to /dev/null.  
The output of your command ./a.out is taken and added to nohup.out (see 
man 1 nohup)

The other way that I have found that you could go is to make a.out a 
daemon.  This involves

1 Chdir to /
2 Close STDIN, STDOUT and STDERR.
3  Forking a new process
4 The parent exits and the child does setsid.


> You should never ever use system(), is's insecure. Use exec*(). However,
> you won't need that - try this:
>
> 	nohup ./a.out > /dev/null 2>&1 < /dev/null &

I believe that you should not need to use this command line.


> It probably dies because of a SIGPIPE if it attempts to read something
> from stdin or if it tries to write to stdout. You break this file
> descriptors in the moment you log off...

Now that might be it I guess.  Having the append >> on your commandline 
may cause this.  When I use nohup the process does not exit but I don't 
use '>> /dev/null'


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-06-30  7:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-29 10:25 a 'wrapper' xlp
2002-06-29 14:49 ` Jan-Benedict Glaw
2002-06-30  7:52   ` Ben Marsh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).