home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!swrinde!gatech!news.byu.edu!ux1!fcom.cc.utah.edu!park.uvcc.edu!ns.novell.com!thisbe.Eng.Sandy.Novell.COM!terry
- From: terry@thisbe.Eng.Sandy.Novell.COM (Terry Lambert)
- Newsgroups: comp.unix.internals
- Subject: Re: How can a Unix process put itself in background?
- Message-ID: <BuDo18.1M9@Novell.COM>
- Date: 10 Sep 92 19:41:31 GMT
- References: <lma.716056953@dayton.Stanford.EDU> <lma.716092591@dayton.Stanford.EDU>
- Sender: usenet@Novell.COM (Usenet News)
- Organization: Novell NPD -- Sandy, UT
- Lines: 51
- Nntp-Posting-Host: thisbe.eng.sandy.novell.com
-
- In article <lma.716092591@dayton.Stanford.EDU> lma@dayton.Stanford.EDU (Larry Augustin) writes:
- >lma@dayton.Stanford.EDU (Larry Augustin) writes:
- >
- >>Someone stopped by my office with this question yesterday.
- >
- >>A user invokes a program at the shell, and interacts with the program
- >>for a short time. Eventually the user selects some "quit" option of
- >>the program. Before the program really quits, it wants to go off and
- >>spend a minute or two checking some database files on disk. Is there
- >>any way for the program to return control to the user's shell while it
- >>does the background stuff? In effect, the program wants to "detach"
- >>itself from stdin/stdout, return control to the shell, and continue in
- >>background for a while before exiting.
- >
- >>The only solutions we could come up with were based on forking a child
- >>to do the background part. is this the only way to do it? Is there a
- >>solution that does not need a fork?
-
-
- Have you tried this to wake the shell up?
-
- kill( getppid(), SIGCHLD);
-
- This is pretty bogus, and I assume that you have a good reason for not using
- a "fork()" where the child dissociates (becomes a child of init) and the
- parent returns to satisfy the wait(4).
-
- This works on some machines, and not on others, and the values returned for
- the exit status of the child from the wait4 are bound to be incorrect
- (unless you link with -lprognosticate 8-) 8-)), and this isn't guaranteed
- to not crash your shell. But it's about the only way to make the shell
- "forget" about a subprocess (by interrupting the mechanism it uses to do
- it's "remembering"). The specific reason it may not work is dependant
- on how the "wait for child death" code is written and the actuality
- itself trapped in the shell. Cruddy shells (shells which can miss a
- child completing if the child exits when multiple background tasks
- occur at around the same time) will probably let you get away with it.
-
- The correct way is to use fork() as part of the procedure. If you'll tell
- us why you don't want to use fork(), perhaps someone in the group can
- tell you why the reasoning is invalid, and suggest a workaround to the
- problem you think you have with fork()?
-
-
- Terry Lambert
- terry_lambert@gateway.novell.com
- terry@icarus.weber.edu
-
- ---
- Disclaimer: Any opinions in this posting are my own and not those of
- my present or previous employers.
-