home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dove!cme!libes
- From: libes@cme.nist.gov (Don Libes)
- Newsgroups: comp.unix.internals
- Subject: Re: How can a Unix process put itself in background?
- Message-ID: <19292@muffin.cme.nist.gov>
- Date: 15 Sep 92 18:37:44 GMT
- References: <lma.716056953@dayton.Stanford.EDU> <lma.716092591@dayton.Stanford.EDU>
- Organization: National Institute of Standards and Technology
- Lines: 37
-
- In article <lma.716092591@dayton.Stanford.EDU> lma@dayton.Stanford.EDU (Larry Augustin) writes:
- }lma@dayton.Stanford.EDU (Larry Augustin) writes:
- }>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?
-
- }The consensus seems to be that it can't be done (without forking), as
- }whatever shell exec'd the program will be stuck in a wait(), and could
- }only continue upon death of the child (or some interaction by the
- }user). There would have to be some other convention for the running
- }program to tell the shell to continue.
-
- Here's a bit of Expect to do this. It works as follows - when you are
- ready to detach the program, you type "~detach". Expect puts itself
- into the background, tells the program to do the "longrunningcommand",
- and when done, tells it to exit gracefully. Obviously Expect is doing
- the fork for you. Nonetheless this is the easiest way to solve the
- whole problem without hacking up the original program. - Don
-
- spawn prog ;# start program
- interact ~detach {
- if [fork] exit ;# parent exits
- disconnect
- send "longrunningcommand\r"
- expect $prompt ;# wait for prog to say it is ready to quit
- send "quit\r" ;# tell program to quit
- expect eof
- }
-