Path: utzoo!attcan!uunet!cs.utexas.edu!usc!apple!veritas!amdcad!sun!datsun!shannon From: shannon@datsun.Sun.COM (Bill Shannon) Newsgroups: comp.unix.shell Subject: Re: Questions about rewriting the History function. Message-ID: <144293@sun.Eng.Sun.COM> Date: 28 Oct 90 00:28:25 GMT References: <1990Oct19.170143.7674@polyof.poly.edu> <32120001@hpfcdc.HP.COM> Sender: news@sun.Eng.Sun.COM Lines: 113 Several people suggested: > You can get asynch job notification in ksh88 by doing: > > trap "jobs -n" CHLD This is almost, but not quite, good enough for what I want. I want to be able to emulate both the csh "set notify" command and the csh "notify" command. The above emulates only the "set notify" command. Here's a message I set to Korn on this subject some time ago: From shannon Sat May 27 02:24:58 1989 To: dgk@ulysses.att.com Subject: traps I'm playing around with trapping SIGCHLD to emulate the csh notify command. the following code in io_intr() causes a newline to be printed every time you execute the trap handler, even if it produces no other output. if(sh.trapnote&TRAPSET) { newline(); fp = st.standin; sh_chktrap(); io_clear(fp); return(0); } for example, do trap true CHLD sleep 5 & there might be cases where the newline is helpful, but in this case it makes it impossible for me to do what I want to do. (that coupled with the fact that functions can't effect the traps of the mainline shell. otherwise I could set and unset the trap when necessary and that might be good enough.) how do you feel about removing that call to newline(), or at least making it conditional on something so it won't happen when catching SIGCHLD? FYI, here's as far as I've gotten with my notify emulation. this works pretty well, but I think there's other problems in the shell that prevent it from working perfectly. for instance, if I do sleep 5 & sleep 5 & notify %1 %2 sometimes it tells me about both jobs and sometimes it loses one of the jobs. any ideas what else could be wrong? trap _notify CHLD NOTIFY_ALL=false unset NOTIFY_LIST _notify() { typeset i j if $NOTIFY_ALL then jobs -n else for i in ${NOTIFY_LIST[*]} do j=`jobs -n %$i` if [ "$j" ] then echo "$j" unset NOTIFY_LIST[$i] fi done fi } notify() { typeset i j if (($# == 0)) then NOTIFY_ALL=true else for i in "$@" do # turn any valid job specification into a job number j=`jobs "$i"` case "$j" in \[*) j=${j%% *} j=${j%\]} j=${j#\[} NOTIFY_LIST[$j]=$j ;; esac done fi } unnotify() { if (($# == 0)) then NOTIFY_ALL=false else # XXX - not done yet : fi }