Loading pid_t into an array for use OUTSIDE of forked process C/linux -
i have have application forks quite few child processes. store these child pid's in array when max_child reached. can kill off oldest ones.
any way of accomplishing ?
note... in real application fork , not wait process finish
here test snippet...
---main
pid_t pid; if ((pid = fork()) < 0) { printf("[*]- error -> fork returned -1\n\n"); } else if (pid == 0) { // success // child process begins here printf("inside child @ pid %i . check ps\n", pid); sleep(30); } else { // still here // maybe store pid global array here? printf("back parent pid: %i child: %i\n\n", getpid(), pid); } // pid comes out 0 here expected printf("pid: %i\n", pid); so store pid int array maybe? how correctly cast pid_t? want able call cleanup() function , have step through list of child pids see if still active, if yes, kill oldest.
any advice appreciated. thank you.
Comments
Post a Comment