1. Terminating parent vs terminating children
Hello all,
Consider the following situation:
A parent process allocates a set of semaphores. It then begins to
spawn children (which use the semaphores). The semaphores are
a global resource and so need to be explicitly destroyed; however
if a *child* process destroys them accidentally then things could
get nasty. So the question becomes: where is the best place to
clean up?
There seem to be two places to put cleanup code: in exit
procedures, which are installed using atexit(), and in signal
functions. In the code that I am patching, the signal functions
for SIGTERM, SIGTRAP, SIGQUIT and SIGINT etc all call
exit() and so atexit() would seem like a good idea. However,
I think I am correct in saying that both signal handlers and
exit procedures are inherited by child processes.
I *could* do the following:
int child_pid = -1;
atexit(MainCleanupProcess);
...
child_pid = fork();
if (child_pid==0)
{
atexit(CleanupChildProcess);
...
with
void MainCleanupProcess(void)
{
if (child_pid != 0)
{
/* destroy semaphores */
}
but I can't shake the feeling that there is probably a better
way of doing this. Can anyone shed any light, please?
(Using portable UNIX...)
Thanks in advance,
Chris.
2. RPX Lite , network problem
3. Problem with ippd ?
4. linksys question...
5. IPPD
6. Windows 95/98 under Linux
7. Solaris 2.5.1 & ISDN & Elsa MicroLink ISDN TLpro
8. Front Page
9. ISDN-Card/ISDN-Router
10. RH5.1, 3com clinet ISDN and Ascend 50 Server ISDN probs
11. SUMMARY: Solaris ISDN, other ISDN and ppp
12. ISDN GW & win95 --> to much ISDN traffic
13. ISDN Sedlbauer PC ISDN Card