c - Wait for child process without freeing its resources -


i looking way access child's task_struct parent when child end, or has ended. reason don't want use wait/waitpid because after wait finished, task_struct , other things freed.

is there way parent wait child process end without calling wait (so task_struct can still accessed zombie process)? ideas can tried?

you can call waitid(2) wnowait flag. here's excerpt manpage:

wnowait

leave child in waitable state; later wait call can used again retrieve child status information.

so, this:

siginfo_t siginfo; if (waitid(p_all, 0, &siginfo, wnowait) < 0) {     // handle error... } else {     // pid of terminated child lives in siginfo.si_pid } 

this makes sure parent blocks until child terminates, still leave child zombie laying around in system.

if want wait specific child process pid x, use waitid(p_pid, x, &siginfo, wnowait).

the child's exit status can retrieved siginfo.si_status. see man waitid learn other fields in siginfo.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -