home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!drizzle.Stanford.EDU!eillihca
- From: eillihca@drizzle.Stanford.EDU (Achille Hui)
- Subject: Re: question on "&"
- Message-ID: <eillihca.712516811@drizzle.Stanford.EDU>
- Sender: news@leland.Stanford.EDU (Mr News)
- Organization: DSO, Stanford University
- References: <1992Jul28.073403.3530@u.washington.edu>
- Date: 30 Jul 92 17:20:11 GMT
- Lines: 58
-
- sue@byron.u.washington.edu (Shu-Chen Eclipse) writes:
-
- >I'm a crass beginnier in unix: I know "&" means something like start a
- >process running in the background, I guess, something like vms's "run/detached";while browsing through some scripts, I saw a line something like
- >(/../.../some file name &)&.
-
- > what does the 2 "&" mean?
- >thanx in advance,
- >sue@byron.u.washington.edu
-
- The 2nd "&" also means running the process in background. Consider the
- following shell script:
-
- #!/bin/sh
- w &
- exec sleep 100
-
- Run this in background and do a "ps", you will discover a process
- marked as <exiting> or something like that. This is the "Zombie" left
- by the process "w". The kernel has release all the resources attached
- to this process except a process slot to hold its exit value. If its
- parent doesn't wait for it, it will be there until its parent die.
- Imagine you have a program that spawn off infinity many background
- sub processes but doesn't wait for it. You will ultimately running
- out of process slots and can't start any new process.
-
- A common trick to avoid such zombies in shell scripts is the
- double fork you have noticed:
-
- ( ProgramInBackground &)&
-
- When the outer shell die, the parent ID of the ProgramInBackground no
- longer valid. The kernel replace this by 1, the process ID of the "init"
- process which is the ancestor of all other process. Since init will
- take care of the exit value of ProgramInBackground when it exits, no
- process slot will be wasted.
-
- By the way, your question is one of the few questions that is appropriate
- for this group. Don't be discouraged by other netters who don't know
- when "RTFM -- Read the F-word Manuals" is the appropriate answer of
- your question.
-
- P.S: If you really want to dig into detail of all this mess. look
- at the manual pages about the system call of exec, fork, wait
- and a very good reference of this stuff is Ch.2 of the book
- UNIX Network programming by W.Richard Stevens.
-
- Hopefully this helps....
- -------------------------------------achille (eillihca@drizzle.stanford.edu)
- JAUU -- Just Another UNIX User.
-
-
-
-
-
-
-
-
-