Xref: utzoo unix-pc.general:2566 comp.sys.att:5994 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ucsd!rutgers!att!icus!lenny From: lenny@icus.islp.ny.us (Lenny Tropiano) Newsgroups: unix-pc.general,comp.sys.att Subject: Re: strange behavior of nohup Summary: disassociate the controlling terminal! Message-ID: <651@icus.islp.ny.us> Date: 31 Mar 89 13:47:31 GMT References: <17168@cisunx.UUCP> Reply-To: lenny@icus.islp.ny.us (Lenny Tropiano) Distribution: usa Organization: ICUS Software Systems, Islip, New York Lines: 59 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 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