* Trapping SIGCHLD
@ 2023-12-03 21:58 Bart Schaefer
0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2023-12-03 21:58 UTC (permalink / raw)
To: Zsh Users
Found the first part of this sitting in my drafts folder from a year
and a half ago.
On Sat, Mar 26, 2022 at 11:10 AM Philippe Troin <phil@fifi.org> wrote:
>
> There may be a way to achieve keeping a set number of children around,
> by trapping SIGCHLD, but we would completely lose the exit status of
> the command.
Is it necessary to grab the exit status right away, or just to obtain
it eventually? If the CHLD trap did nothing but decrement a counter
every time a child exited, a new child could start right away,
increment the counter, and then (possibly much) later an explicit
"wait $childpid" could be done.
> There does not seem to be a way to retrieve the exit
> status of a command as soon as SIGCHLD is trapped
It's a bit round-about, but:
watchCHLD() {
setopt localoptions nonotify
trap 'print -p wakeup; trap - CHLD' CHLD
coproc read -E
read -p
}
waitchild () {
watchCHLD
wait $1
}
() { sleep 20; return 23 } & waitchild $!
print $?
If/when the patch from workers/52365 goes in, it'll be possible to get
the status of a specific PID in the CHLD trap itself. However, if
multiple children exit at the same time the CHLD handler may be called
only once, so some trickery with $jobstates is necessary. If this is
still of interest I'll try to work out details.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-12-03 21:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-03 21:58 Trapping SIGCHLD Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).