Trouble writing background-running program
- From: Carlos Moreno <cm_news@xxxxxxxxxxxxxx>
- Date: Sun, 23 Mar 2008 19:31:20 -0700 (PDT)
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
--
.
- Follow-Ups:
- Re: Trouble writing background-running program
- From: LEE Sau Dan
- Re: Trouble writing background-running program
- From: Tauno Voipio
- Re: Trouble writing background-running program
- From: Guido Scholz
- Re: Trouble writing background-running program
- Prev by Date: Re: autoreconf: g++ compiler options in configure.ac
- Next by Date: Re: Trouble writing background-running program
- Previous by thread: A few places left at Embedded Linux Workshop
- Next by thread: Re: Trouble writing background-running program
- Index(es):