On 1/2/12 2:10 PM, Stas Sergeev wrote: >>> Will your suggestion about the trap handler work >>> also for ^Z+bg rather than just fg? >> It should. > I tried: > --- > trap bg USR1 > --- > Now if I first send SIGSTOP to the job and then SIGUSR1 to > bash, that works. > Is it possible to avoid sending SIGSTOP to the job, and make > the trap handler to do both things at once? Not that it is strictly > required since you already described a few other ways, but I wonder. :)
Well, this is getting pretty esoteric. On one hand, you can avoid the entire SIGSTOP/SIGCONT issue by initially starting the job in the background with `&'. On the other, if you want to move a foreground job to the background, you have to get it to give up control somehow, and sending it a signal is the way to do that. You can install a trap handler for another signal, say SIGALRM, and have some process send SIGALRM to the shell after some period (e.g., `( sleep 20 ; kill -ALRM $$)' ), but you'll have to get the shell to react to the signal once it's received rather than waiting for the foreground process to change state. Once you get the shell running, it can issue the SIGSTOP/bg. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/