jcbst3@cisunx.UUCP (James C. Benz) (03/30/89)
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. Once this is done, the hung window disappears and everything is back to normal. So what am I missing? Is there some other way to accomplish this that won't leave dead windows lying around? ps -eaf shows that the parent process for the nohuped process is 1, not the shell that invoked it, so it seems right, but the window hangs every time. Is there a bug here, or am I missing something in the documentation? Any suggestions would be appreciated. Thanks -- Jim Benz jcbst3@unix.cis.pittsburgh.edu If a modem University of Pittsburgh answers, UCIR (412) 648-5930 hang up!
ditto@cbmvax.UUCP (Michael "Ford" Ditto) (03/31/89)
In article <17168@cisunx.UUCP> jcbst3@unix.cis.pittsburgh.edu (James C. Benz) writes: >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. Once this is done, the hung window disappears and Try: nohup demon options 1>/dev/null 2>/dev/null 0</dev/null & The window will stay around as long as something has it open, and your "demon" will have the window open as its standard input. The window is not "hung" at all, it's just that once your shell exits, there is no program reading what you type. If your "demon" program ever reads from stdin, it would read whatever you typed in the window. Adding the stdin redirection as I show above should make everything work as you expect. -- -=] Ford [=- "This is yet another example of how In Real Life: Mike Ditto) our actions have random results." ford@kenobi.cts.com - Cmdr. Data ("Contagion") ...!sdcsvax!crash!elgar!ford ditto@cbmvax.commodore.com
lenny@icus.islp.ny.us (Lenny Tropiano) (03/31/89)
In article <17168@cisunx.UUCP> jcbst3@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@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