From: "David Schwartz" <davids@webmaster.com>
To: <lgb@lgb.hu>, <linux-kernel@vger.kernel.org>
Subject: RE: fork(): parent or child should run first?
Date: Wed, 11 Jan 2006 17:33:13 -0800 [thread overview]
Message-ID: <MDEHLPKNGKAHNMBLJOLKKECAJFAB.davids@webmaster.com> (raw)
In-Reply-To: <20060111123745.GB30219@lgb.hu>
> The following problem may be simple for you, so I hope someone can answer
> here. We've got a complex software using child processes and a table
> to keep data of them together, like this:
>
> childs[n].pid=fork();
>
> where "n" is an integer contains a free "slot" in the childs struct array.
>
> I also handle SIGCHLD in the parent and signal handler searches
> the childs
> array for the pid returned by waitpid(). However here is my problem. The
> child process can be fast, ie exits before scheduler of the kernel give
> chance the parent process to run, so storing pid into childs[n].pid in the
> parent context is not done yet. Child may exit, than scheduler
> gives control
[snip]
There are a lot of things you should not do in a signal handler, this is
one of them. There are a lot of possible solutions. My recommendation would
be to handle the death of a child from a safe context, rather than from a
signal handler. For example, the SIGCHLD handler could just set a volatile
variable to 'true' and then the code could notice that from a safe context
and loop on 'waitpid', reaping all dead children.
DS
prev parent reply other threads:[~2006-01-12 1:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-11 12:37 OT: " Gábor Lénárt
2006-01-11 12:51 ` Arjan van de Ven
2006-01-11 13:02 ` Gábor Lénárt
2006-01-11 13:25 ` Bernd Petrovitsch
2006-01-11 13:49 ` Ian Campbell
2006-01-11 13:55 ` Bernd Petrovitsch
2006-01-11 14:05 ` Ian Campbell
2006-01-11 15:19 ` linux-os (Dick Johnson)
2006-01-12 1:33 ` David Schwartz
2006-01-12 1:38 ` Kurt Wall
2006-01-12 17:23 ` Hugh Dickins
2006-01-12 20:19 ` Gábor Lénárt
2006-01-11 13:34 ` Roland Kuhn
2006-01-11 17:11 ` Lee Revell
2006-01-11 13:03 ` Miquel van Smoorenburg
2006-01-11 13:08 ` Jan-Benedict Glaw
2006-01-12 1:33 ` David Schwartz [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=MDEHLPKNGKAHNMBLJOLKKECAJFAB.davids@webmaster.com \
--to=davids@webmaster.com \
--cc=lgb@lgb.hu \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®