Re: Trouble writing background-running program
- From: Tauno Voipio <tauno.voipio@xxxxxxxxxxxxx>
- Date: Mon, 24 Mar 2008 19:56:37 GMT
Carlos Moreno wrote:
I'm trying to write a program that runs in the background, but I'm
puzzled by one
detail --- one aspect in the behaviour that I don't understand.
I connect remotely to the server (using an X-terminal on my local
machine
running GNOME) through SSH to run the program.
No matter what I do, after I run the program, my console seems to hold
on to
the connection and doesn't let go.
I run the program and then I run logout or Ctrl-D, and the X-terminal
does not
return to my local shell. If I close it forcibly (kill or simple the
close button of
the window), then ok, and the remote process does remain running in
the
background.
This happens if I run the program with &, with nohup --- even with a
double &
as in: [ prompt ]$ (./program &) & (or through a script that runs
it with & and
I run the script with & )
I of course tried to code the program to work as a daemon, following
the little
recipe and explanations from Stevens' Advanced Programming in the
Unix
Environment (1993 edition) --- I fork, close the parent, then in the
child I call
setsid() ... I skip the rest since my program changes to its "native"
directory
anyway, and it never creates files or directories, so the umask part
is also
unneeded).
The behaviour is exactly the same. Stevens mentions something about
closing any file descriptors, etc.... I figured I'd try closing stdin/
out/err *in the
parent* before exiting --- I call close(0); close(1); close(2);
before exiting
from the parent --- no effect; the behaviour remains the same.
Any hints as to what I'm missing? (it does work as expected if I run
from
the console some of the usual services --- apache, sendmail, etc.)
Help??
Thanks!
Carlos
--
To save some extra work, have a look at the daemon() library
routine (man daemon).
--
Tauno Voipio
tauno voipio (at) iki fi
.
- References:
- Trouble writing background-running program
- From: Carlos Moreno
- Trouble writing background-running program
- Prev by Date: Re: coding text editor
- Next by Date: Re: comparing algorithm perf.
- Previous by thread: Re: Trouble writing background-running program
- Next by thread: Re: Trouble writing background-running program
- Index(es):