On 24 Jan 2001, at 20:12, Charles Steinkuehler wrote:

> Take a look at my shell-script e-mail client, where I do pretty
> much what you want, with a few extra features (look for the mail
> procedure):
> http://lrp.steinkuehler.net/Packages/files/Utilities/grep 

Thanks I'll look...

> The mainline code fires off a couple sub-processes that acutally
> does the work.  The main code then goes into a timeout loop (sleeps
> for 1 second, increments a counter, checks to see if the children
> have finished).  If the timeout counter ever expires, the mainline
> code kills all the (presumably hung) children.  The child process
> can send a signals to the mainline code to indicate it's still
> alive, but things are taking a while, or that a problem has occured
> and we should promptly exit. 

In my situation, the "sleeper" process is a spawned process; in 
your case, the "sleeper" is the process which spawned the others.  
I don't know if I could flip things around, since I require the script to 
have access to the tty and to stdin - which a background process 
won't - it would say "process X stopped [tty input]" or something 
like that.

I've considered pipes or file-based locks/communications, but that 
seems like overkill.

Maybe if I had specific questions:

* If a process is killed, are all of the children killed?  If not, how do I 
do this?

* If I want to have a parent process exit before the child is done, 
how do I do this?

* The program sleep doesn't seem to abort if it's parent (?) is sent a 
signal.  How do I get the signal to propogate?

.................................Ummm...

For discussion's sake, I think I'll leave those questions in there.  
My answer was this program:

killall sleep

and a well-placed redirection or two, as well as ignoring signals.  
Here is the revised method:

1. Spawn a sleeper process: sleep X ; kill -1 $$
2. trap on 0 1 2 15
3. get input
4. three possible actions:
      4a. receive input: exit normally, print input to stdout - to be 
captured by VAR=$(timedread <n> <prompt>)....
      4b. receive interrupt signal (^C) - exit status 2
      4c. timedout: exit status 1

The standard exit is this:

trap '' 1 2 15   # ignore signals - such as those generated by killall
killall sleep 1>&2 2> /dev/null # kill current sleep (quietly! even if 
error)
exit with status

The sleeper process was more completely this:

( sleep 2>&1 > /dev/null ; kill -1 $$ 2>&1 > /dev/null ) 1>&2 2> 
/dev/null &

In other words, TOTAL silence :-)

How does this differ from what you did?

-- 
David Douthitt
UNIX Systems Administrator
HP-UX, Linux, Unixware
[EMAIL PROTECTED]

_______________________________________________
Leaf-devel mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/leaf-devel

Reply via email to