[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: What is the rational for posix2 requierment that system(char*) blocks sigchld?



e2xbegqsdyt21hfc wrote:
According to

    man 3 system

, sigchld is blocked while system(char*) is executing.
As far as I can tell this is a requirement imposed by
posix2.
  What is the rational for blocking this signal?

I suppose that's a type for "rationale".

If the signal were delivered while the system(.) service
were running, then it would be difficult to schedule
waiting for it. To put it another way, it creates
a rendezvous between the two executing threads which any
process wanting to wait for child would have to create
by hand. A race condition is created, otherwise.

Perhaps you haven't thought it through. The parent
process is still inside the system(.) service when the
child dies. You want to hold off delivery until after
system(.) returns.[*]

Here's a timeline presuming another process gets created
and some other program executes...

parent invokes system(.)
system(.) creates a child
parent suspends inside system(.)

child wakes up and does something
child dies
OS sends SIGCHLD to parent, but no delivery

parent wakes up inside system(.)
system(.) cleans up from creation of child
parent returns froms system(.)
parent receives SIGCHLD

We don't want system(.) to be burdened with being conformant
with whatever signal handler for SIGCHLD may be written by the
user and in effect. Otherwise it would look like this:

parent invokes system(.)
system(.) creates a child
parent suspends inside system(.)

child wakes up and does something
child dies
OS sends SIGCHLD to parent
OS delivers SIGCHLD to parent

parent wakes up inside system(.) and runs code
  that we don't know what it is or have any control
  over what it does
system(.) has to try to continue recovering context
  from creating the child, in spite of whatever
  the signal handler may have done
parent returns froms system(.)

[*] Unless the system(.) invokes something in a way
which allows the parent to continue execution. But the
same considerations would still apply, just not guaranteed.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!



Reply to: