[comp.unix.questions] Background processes on logout

F66204@BARILVM.BITNET (Shaul Wallach) (02/21/91)

   Please excuse this beginner's question. Is there any way for a
user to log out of a UNIX system (say AIX/6000) while leaving
background processes active? My experience seems to be that the
logout command kills all background processes, something I want
to prevent.

Thanks,

Shaul Wallach

jik@athena.mit.edu (Jonathan I. Kamens) (02/21/91)

  "man nohup".

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

phil@ux1.cso.uiuc.edu (Phil Howard KA9WGN) (02/21/91)

F66204@BARILVM.BITNET (Shaul Wallach) writes:

>   Please excuse this beginner's question. Is there any way for a
>user to log out of a UNIX system (say AIX/6000) while leaving
>background processes active? My experience seems to be that the
>logout command kills all background processes, something I want
>to prevent.

Another poster replied "man nohup".  If the background processes are dying
because of a HUP condition, that can be fixed.

However I've found that the shell often kills these processes.  Some do it
only to stopped processes and some seem to (unsociably) do this to running
processes.

I use the following trick in csh to hide background processes from the
shell:

    ( command and arguments & )

By doing:

    ( command and arguments & ) < /dev/null >& /dev/null

it won't even have the tty open unless it intentionally opens it.  In that
case you could execute the above via rsh to your local host and then there
will be no tty.  Be sure to use the /dev/null redirections to avoid rsh
waiting for a network connection to close:

    rsh `hostname` "( command and arguments & ) < /dev/null >& /dev/null"

The shown syntaxes are for csh.  Users of sh and ksh should adapt (however
it is those do it).

I just tried this on AIX/6000 and it works.
-- 

--Phil Howard, KA9WGN-- | Individual CHOICE is fundamental to a free society
<phil@ux1.cso.uiuc.edu> | no matter what the particular issue is all about.

ndh@stl.stc.co.uk (Neale D Hind ) (02/21/91)

In the referenced article F66204@BARILVM.BITNET (Shaul Wallach) writes:
>
>   Please excuse this beginner's question. Is there any way for a
>user to log out of a UNIX system (say AIX/6000) while leaving
>background processes active? My experience seems to be that the
>logout command kills all background processes, something I want
>to prevent.

On our System V system we use "nohup command &".  If you logout and
then log back in and "ps -fu<logname>" the process is running with
parent process UID of 1.


----
Neale D. Hind - (N.D.Hind@stl.stc.co.uk)

dfraser@libws1.ic.sunysb.edu (David W Fraser) (02/22/91)

In article <91051.180110F66204@BARILVM.BITNET> F66204@BARILVM.BITNET (Shaul Wallach) writes:
>
>   Please excuse this beginner's question. Is there any way for a
>user to log out of a UNIX system (say AIX/6000) while leaving
>background processes active? My experience seems to be that the
>logout command kills all background processes, something I want
>to prevent.
>
>Thanks,
>
>Shaul Wallach

Well I have the opposite problem.  I am using HP-UX 7.0, and when I logout my
background processes continue running.  Is there any way I can prevent this?
Such as adding something to my .logout file?

Thanks

Dave Fraser

     \\\|||///       _____________________________________
   .  =======     _ /           David W. Fraser           \
  / \| O   O |   /_|            ~~~~~~~~~~~~~~~            |
  \ / \`___'/  -</ |Internet: dfraser@csserv1.ic.sunysb.edu|
   #   _| |_       |          dfraser@ccvm.sunysb.edu      |
  (#) (     )      |Bitnet:   dfraser@sbccvm               |
   #\//|* *|\\     |                                       |
   #\/(  *  )/     |MaBellnet:(516)-632-1366               |
   #   =====       |                                       |
   #   ( U )       |       SUNY @ Stony Brook, LI NY       |
   #   || ||        \_____________________________________/
  .#---'| |`----.
  `#----' `-----'

tchrist@convex.COM (Tom Christiansen) (02/22/91)

From the keyboard of dfraser@libws1.ic.sunysb.edu (David W Fraser):
:In article <91051.180110F66204@BARILVM.BITNET> F66204@BARILVM.BITNET (Shaul Wallach) writes:
:>
:>   Please excuse this beginner's question. Is there any way for a
:>user to log out of a UNIX system (say AIX/6000) while leaving
:>background processes active? My experience seems to be that the
:>logout command kills all background processes, something I want
:>to prevent.
:>
:>Thanks,
:>
:>Shaul Wallach
:
:Well I have the opposite problem.  I am using HP-UX 7.0, and when I logout my
:background processes continue running.  Is there any way I can prevent this?
:Such as adding something to my .logout file?

It's a matter of shells and process groups and job control.  The csh puts background
jobs in different process groups.  When you log out, stopped jobs die but those
running continue doing so.  Those of us accustomed to this behavior think anything
else is a pain.  If you want them to die, you should hunt them down and kill them,
or make them do something like check to see when getppid() goes to 1 (orphaned
procs get inherited by init.)

On the other end of the spectrum is sh, who doesn't switch process groups on 
backgrounded commands, and who kills all its children when you logout.  To 
avoid this, there's a nohup prefix command that you can use to get around this.
I would really hate this behavior.  I don't want by running background jobs to
die just because the phone line glitches.

There may be some sloppiness in the above explanations, but I believe them 
to be essentially correct.

--tom
-- 
"UNIX was not designed to stop you from doing stupid things, because
 that would also stop you from doing clever things." -- Doug Gwyn

 Tom Christiansen                tchrist@convex.com      convex!tchrist

gwyn@smoke.brl.mil (Doug Gwyn) (02/22/91)

In article <91051.180110F66204@BARILVM.BITNET> F66204@BARILVM.BITNET (Shaul Wallach) writes:
-   Please excuse this beginner's question. Is there any way for a
-user to log out of a UNIX system (say AIX/6000) while leaving
-background processes active? My experience seems to be that the
-logout command kills all background processes, something I want
-to prevent.

Look up "nohup" in the user's manual.

dougw@fdls.odag.or.gov (Doug Walker) (02/22/91)

In <1991Feb20.211507.28547@ux1.cso.uiuc.edu> phil@ux1.cso.uiuc.edu (Phil Howard KA9WGN) writes:

>F66204@BARILVM.BITNET (Shaul Wallach) writes:

>>   Please excuse this beginner's question. Is there any way for a
>>user to log out of a UNIX system (say AIX/6000) while leaving
>>background processes active? My experience seems to be that the
>>logout command kills all background processes, something I want
>>to prevent.

The most reliable method we have found is to submit the program as a job
through at/batch.  Then, you can logout with no impact on the ultimate
completion of the job.  For example, let's say you have a program myprog that
is designed to operate in the background.  Then, the following line will
submit the program to at to run whenever the system resources are available:

     myprog | batch

One caveat is that you would have to have permission to use the at facility.
We have chosen to permit all users to use at by having a file
/usr/lib/cron/at.deny with zero length and have removed the file
/usr/lib/cron/at.allow.  Do a man on at to get the particulars for your
system.

Hope this helps.
-- 
-----------------------------------------------------------------------------

Doug Walker               uunet!fdls!dougw  -or-  dougw@fdls.odag.or.gov
Oregon Department of Agriculture, Salem, Oregon           (503) 378-3790

jik@athena.mit.edu (Jonathan I. Kamens) (02/22/91)

In article <1991Feb21.164300.3596@sbcs.sunysb.edu>, dfraser@libws1.ic.sunysb.edu (David W Fraser) writes:
|> Well I have the opposite problem.  I am using HP-UX 7.0, and when I logout my
|> background processes continue running.  Is there any way I can prevent this?
|> Such as adding something to my .logout file?

  I don't know if HP-UX supports the sending of a signal to "process" -1 in
order to send it to all of the processes to which the user is allowed to send
signals, but if it does, then you should be able to do "kill -1 -1" in your
.logout file.  Here's what our man page for the kill system call says about
this:

     If the process number is -1 and the user is the super-user,
     the signal is broadcast universally except to system
     processes and the process sending the signal.  If the pro-
     cess number is -1 and the user is not the super-user, the
     signal is broadcast universally to all processes with the
     same uid as the user except the process sending the signal.
     No error is returned if any process could be signaled.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

barmar@think.com (Barry Margolin) (02/23/91)

In article <1991Feb22.035953.29266@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes:
>  I don't know if HP-UX supports the sending of a signal to "process" -1 in
>order to send it to all of the processes to which the user is allowed to send
>signals, but if it does, then you should be able to do "kill -1 -1" in your
>.logout file.

Sounds like a good idea for a manual command, but not for a .logout file,
if you ever login on more than one terminal.  If you're logged in twice and
use that command you'll kill all the processes on both terminals.
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

rad@genco.bungi.com (Bob Daniel) (02/26/91)

In article <91051.180110F66204@BARILVM.BITNET> F66204@BARILVM.BITNET (Shaul Wallach) writes:
>
>   Please excuse this beginner's question. Is there any way for a
>user to log out of a UNIX system (say AIX/6000) while leaving
>background processes active? My experience seems to be that the
>logout command kills all background processes, something I want
>to prevent.

Use 'nohup' (no hangup) before starting up the process.  The process will 
continue after logging off.  There are limitations.  Check your manual on
this command.  This is basically what you want though.

elston@edwards-saftd-2.af.mil (03/02/91)

>From: F66204@BARILVM.BITNET (Shaul Wallach)
>Subject:Background processes on logout
>Date: 20 Feb 91 16:53:07 GMT
>Message-ID:<91051.180110F66204@BARILVM.BITNET>

>
>   Please excuse this beginner's question. Is there any way for a
>user to log out of a UNIX system (say AIX/6000) while leaving
>background processes active? My experience seems to be that the
>logout command kills all background processes, something I want
>to prevent.
>
>Thanks,
>
>Shaul Wallach
-- 

Try using 'nohup ' on the command line prior to the command.  This will return
a process id and will allow the program (binary or shell script) - if run in
the background - to continue after termination of the parent process.


Mark E.

##############################################################################
#    .                                                                       #
#    .      Mark Elston                   Keep on smiling --                 #
# .......   NSI, Inc.                          If you knew the full truth    #
#    .      Edwards AFB, CA                    you'd cry like a baby.        #
#    .                                                                       #
#    .                                          ;-) ;-) ;-) ;-) ;-)          #
#    .     elston@edwards-saftd-2.af.mil                                     #
##############################################################################

greywolf@unisoft.UUCP (The Grey Wolf) (03/07/91)

<1991Feb23.091836.14043@Think.COM> by barmar@think.com (Barry Margolin)
& In article <1991Feb22.035953.29266@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes:
& >  I don't know if HP-UX supports the sending of a signal to "process" -1 in
& >order to send it to all of the processes to which the user is allowed to send
& >signals, but if it does, then you should be able to do "kill -1 -1" in your
& >.logout file.
& 
& Sounds like a good idea for a manual command, but not for a .logout file,
& if you ever login on more than one terminal.  If you're logged in twice and
& use that command you'll kill all the processes on both terminals.

Ah, but you see, "kill" is a csh builtin.  So it will just kill off
everything that is yours *except* the csh.

The original request also seems to be unclear as to whether by backgrounded
he means addressable as %2, %3, etc, or completely daemonized.  If it's
daemonized, then he should be a little more responsible about making sure
that the programs check that the ppid is what it was when it started.

I would give anything for the Pyramid OSx to have "kill -1" functionality
in the kernel!

& --
& Barry Margolin, Thinking Machines Corp.
& 
& barmar@think.com
& {uunet,harvard}!think!barmar


-- 
# On the 'Net:  Why are more and more fourth-level wizard(-wannabe)s trying
# to invoke ninth-level magic instead of taking the time to climb the other
# (quite essential) thirteen or fourteen levels so they can do this properly?
# ...!{uunet,ucbvax}!unisoft!greywolf

t891368@minyos.xx.rmit.oz.au (Mark) (03/12/91)

Occasionally when connecting to a remote site one gets disconnected and has to 
telnet back and relogin. Occasionally for some reason unknown to myself the
old process still exists and is just sitting there.

Question:
 Is there a way of recovering the job to the foreground.? It doesnt exists
 on 'jobs' (using tcsh on 4.3BSD) and usually I just kill -9 <pid>
 Can I regain control of it?

Mark.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Mark Matthewson                     Long distance runners can keep going longer
t891368@minyos.xx.rmit.oz.au             Is your job secure?
mark@albert.ai.mit.edu                   Do you have the code to prove it?
P.O. Box 487 Essendon Australia 3040     Phone: Yes      IrcNick: Mark
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

jik@athena.mit.edu (Jonathan I. Kamens) (03/13/91)

In article <1991Mar12.024121.9114@minyos.xx.rmit.oz.au>, t891368@minyos.xx.rmit.oz.au (Mark) writes:
|> Question:
|>  Is there a way of recovering the job to the foreground.? It doesnt exists
|>  on 'jobs' (using tcsh on 4.3BSD) and usually I just kill -9 <pid>
|>  Can I regain control of it?

  No, not unless you used the "screen" package (see comp.sources.unix
archives) or something similar to start up your shells in a way that allows
them to be detached from and reattached to your terminal.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710