GWEN_PROCESS_STATE GWEN_Process_GetState(GWEN_PROCESS *pr, int w) { int rv; int status; assert(pr); /* try to get the status */ rv=waitpid(pr->pid, &status, w?0:WNOHANG); if (rv==-1) { DBG_ERROR(GWEN_LOGDOMAIN, "waitdpid(%d): %s", (int)pr->pid, strerror(errno)); return GWEN_ProcessStateUnknown; } else if (rv==0) { /* process still running */ return GWEN_ProcessStateRunning; } else { return GWEN_Process_MakeState(pr, status); } }
void GWEN_Process_SignalHandler(int s) { int status; pid_t pid; switch (s) { case SIGCHLD: /* try to get the status */ pid=waitpid(0, &status, WNOHANG); if (pid==-1) { DBG_DEBUG(GWEN_LOGDOMAIN, "waitdpid(%d): %s", 0, strerror(errno)); } else if (pid==0) { /* process still running ?! */ DBG_DEBUG(GWEN_LOGDOMAIN, "Got a SIGCHLD but no child terminated ??"); } else { GWEN_PROCESS *pr; /* som process terminated */ pr=GWEN_Process_FindProcess(pid); if (!pr) { DBG_NOTICE(GWEN_LOGDOMAIN, "No infomation about process \"%d\" available", (int)pid); } else { GWEN_Process_MakeState(pr, status); /* remove from list. If this process data is not used by the * aplication it will now be freed, otherwise only the usage * counter is decremented */ GWEN_Process_free(pr); } } break; default: DBG_ERROR(GWEN_LOGDOMAIN, "Got unhandled signal \"%d\"", s); break; } /* switch */ }