On Wed, Mar 27, 2013 at 6:10 PM, Roland Mainz <[email protected]> wrote: > On Wed, Mar 27, 2013 at 11:31 AM, Irek Szczesniak <[email protected]> > wrote: > [snip] >>>> BTW: The patch currently doesn't cover passing SIGCHLD siginfo data to >>>> the shell traps (this needs to be done in |job_waitsafe()| ... but >>>> that may be tricky). >>> >>> Could you add.sh.status (Exit value or signal) and .sh.pid for CHLD >>> traps, please? >> >> Appending to this RFE: >> We like to have .sh.code for CHLD traps too, with .sh.code being a >> STRING returning one of the CLD_* codes defined in >> http://pubs.opengroup.org/onlinepubs/7908799/xsh/signal.h.html (i.e. >> this is defined by X/OPEN and POSIX and therefore should be applicable >> as shell extension). > > Erm... do you mean that you want to be able to write a ksh93 version > of the following C code ? > -- snip -- > #include <stdlib.h> > #include <stdio.h> > #include <signal.h> > #include <sys/types.h> > #include <unistd.h> > #include <errno.h> > > static > const char *sicode2str(int si_code) > { > const char *str; > switch(si_code) > { > #define STRSYM(sym) \ > case (sym): str = #sym ; break; > STRSYM(CLD_EXITED) > STRSYM(CLD_KILLED) > STRSYM(CLD_DUMPED) > STRSYM(CLD_TRAPPED) > STRSYM(CLD_STOPPED) > STRSYM(CLD_CONTINUED) > default: > str="<unknown>"; > break; > } > return str; > } > > > static > void chld_handler (int signum, siginfo_t *si, > void *context) > { > printf("#SIGCHLD, si_code=%d/%s handler\n", > si->si_code, > sicode2str(si->si_code)); > } > > > static > void chsleep(void) > { > int i; > for (i=0 ; i < 120 ; i++) > usleep(10000); > } > > > int main(int ac, char *av[]) > { > struct sigaction new_action; > pid_t pid; > > /* Setting-up the sigchld handler */ > new_action.sa_sigaction = chld_handler; > sigemptyset (&new_action.sa_mask); > new_action.sa_flags = SA_SIGINFO; > sigaction (SIGCHLD, &new_action, NULL); > > pid = fork(); /*FIXME: Need error handling*/ > > if (pid == 0) > { > /* Child process */ > > puts("# child process " > "(stopping now...)"); > raise(SIGSTOP); > > puts("# child continues..."); > > _exit(0); > } > else > { > /* Parent process */ > > chsleep(); > puts("# parent waking child..."); > kill(pid, SIGCONT); > chsleep(); > } > > return EXIT_SUCCESS; > } > -- snip -- > > The output should look like this: > -- snip -- > # child process (stopping now...) > #SIGCHLD, si_code=5/CLD_STOPPED handler > # parent waking child... > # child continues... > #SIGCHLD, si_code=6/CLD_CONTINUED handler > #SIGCHLD, si_code=1/CLD_EXITED handler > -- snip -- > > This should be technically possible to implement in ksh93... but for > which purpose are you interested in the |CLD_STOPPED|&co. codes ?
Until now there is no scalable way to monitor only a single process in a pool of many (20000+) worker processes. The usual way of listening to the CHLD trap and then take a sample of the job list using jobs -l works but scales very poorly. Using the information solely from the siginfo data passed to the CHLD handler would avoid that scalability bottleneck. Looking at si_code reveals whether the child process completed successfully, crashed or somehow else changed state and is thus IMO mandatory to replace jobs -l as information source. Irek _______________________________________________ ast-developers mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-developers
