Skip to contentSkip to conversation

a 'wrapper'

DISCUSSION xlp 3 participants 3 messages Jun 29, 2002 – Jun 30, 2002

lore
Share & tools
lore

xlp

author
#0 lore raw

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.

#1 lore raw

On Sat, 2002-06-29 05:25:02 -0500, xlp <[email protected]> wrote in message <20020629052348.A50622@nietzsche>:

Quoted 5 lines

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

Signature · 3 lines
Jan-Benedict Glaw   .   [email protected]   .   +49-172-7608481
	 -- New APT-Proxy written in shell script --
	   http://lug-owl.de/~jbglaw/software/ap2/
#2 lore raw

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

Quoted 7 lines · Jan-Benedict Glaw

On Sat, 2002-06-29 05:25:02 -0500, xlp <[email protected]> wrote in message <20020629052348.A50622@nietzsche>:

Quoted 5 lines

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.

Quoted 4 lines

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.

Quoted 3 lines

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'