On Sunday, March 17, 2013 07:08:25 PM Lionel Cons wrote:
> I found this very cool but undocumented (why?) feature that you can
> find the sender of a signal and pass a value (for realtime signals):
> ~/bin/ksh -c 'compound pc ; trap "pc.value=\${.sh.sig.value}
> pc.pid=\${.sh.sig.pid}" RTMIN ; integer thispid=$$ ; kill -q 16#23456
> -RTMIN $thispid &  ; wait ; printf "%s\n" "${pc}"'
> (
>         pid=984
>         value=16#23456
> )
> 
> Now I thought this could be used create scripts which handle SIGCHLD
> in an event-driven manner, but the concept doesn't work for SIGCHLD
> traps:
> ~/bin/ksh -c 'compound pc=( integer value=-1 pid=-1 ) ; trap
> "pc.value=\${.sh.sig.value} pc.pid=\${.sh.sig.pid} ; print trapCHLD"
> CHLD ; integer thispid=$$ ; sleep 2 &  ; wait ; printf "%s\n" "${pc}"'
> trapCHLD
> (
>         typeset -l -i pid=0
>         typeset -l -i value=0
> )
> 
> Why does that happen?
> 
> Lionel
> _______________________________________________
> ast-developers mailing list
> [email protected]
> http://lists.research.att.com/mailman/listinfo/ast-developers

ksh93's wait unfortunately only can behave like Bash's non-POSIX mode wait. In 
Bash POSIX mode, and also mksh, setting a trap on CHLD causes the wait to 
trigger on the completion of any job (when job control is enabled). The next 
version of Bash is also adding a `wait -n' flag to accomplish this sort of 
thing (and guarantee no race issues).

This script demonstrating simple events works in Bash and mksh, but not ksh93:
https://gist.github.com/ormaaj/3911059

-- 
Dan Douglas
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to