strange behavior of nohup
Lenny Tropiano
lenny at icus.islp.ny.us
Fri Mar 31 23:47:31 AEST 1989
In article <17168 at cisunx.UUCP> jcbst3 at unix.cis.pittsburgh.edu (James C. Benz)
writes:
|>I have been trying to write a shell script that invokes a home-brew demon
|>process for an application I've been working on. On other Unix systems
|>I've worked on, (3B2) the nohup command allows you to log out of the
|>current shell level without killing the nohuped process. My shell script
|>on the UNIXPC has a line that goes something like this:
|>
|>nohup demon options 1>/dev/null 2>/dev/null&
|>
|>Having executed this line and exiting back to the $ prompt, I then press
|>^D to exit the shell. Normally, this would get me back to the ua window
|>environment, but after running the nohup, ^D hangs the Full-screen Unix
|>window (Sys V version 3.51) and the only way I can get rid of it is to
|>open another Unix window and explicitly kill the demon process that was
|>run with the nohup.
...
This happens a lot, especially when you write "demon-type" programs that
are supposed to stay around for a while. On the 3B2 there is a command
called "setpgrp" which in turn calls the setpgrp(2) system call. I
wrote the quick equivalent for the UNIX pc. Basically it calls the program
specified on the command line with all the arguments after it does
a setpgrp(2) system call, which will disassociate the controlling terminal
from the process (changing the process group). Instead of having a
"w1" or "w3" or whatever in the "ps -ef" you should have a "?".
Invoke your command with:
$ setpgrp nohup demon options >/dev/null 2>&1 &
This is also good for fixing crons that run that shouldn't be associated
with the controlling terminal (and in turn receiving all the controlling
terminals signals).
-Lenny
-- cut here for setpgrp.c -- -- cut here for setpgrp.c --
#include <stdio.h>
main(argc,argv,envp)
int argc;
char *argv[], *envp[];
{
if (argc < 2) {
fprintf(stderr,"Usage: %s program [argv ... ]\n",
argv[0]);
exit(1);
}
setpgrp(0);
execvp(argv[1], &(argv[1]));
perror(argv[0]);
}
--
Lenny Tropiano ICUS Software Systems [w] +1 (516) 582-5525
lenny at icus.islp.ny.us Telex; 154232428 ICUS [h] +1 (516) 968-8576
{talcott,decuac,boulder,hombre,pacbell,sbcs}!icus!lenny attmail!icus!lenny
ICUS Software Systems -- PO Box 1; Islip Terrace, NY 11752
More information about the Unix-pc.general
mailing list