[plug] Killing process after time

Leon Brooks leon at brooks.fdns.net
Mon May 31 10:53:09 WST 2004


On Mon, 31 May 2004 10:34, Bernard Blackham wrote:
> The usleep will probably work in 99.9% of cases, but race conditions
> like to occur in that last 0.1% of cases ... just being picky :)

The usleep relinquishes the child's timeslice. In order for your race 
condition to be met, the parent (which always gets a turn before the 
child does unles you're running a really bizarre scheduler) has to fail 
to execute a return (from the fork()), a conditional branch, and 
signal() syscall in one timeslice. Even if the child relinquishes the 
CPU right at the end of a scheduling clock period, it would again be 
put to sleep for at least a microsecond, which would still result in 
the parent being scheduled before it.

On a multiprocessor machine, the child would be on a separate processor 
and would immediately do an exec(), an operation which *has* to be much 
slower than return, branch, signal() even just in the argument-parsing 
stage, so say nothing of traipsing through the $PATH and loading a 
separate program. The only alternative is for the exec() to fail, in 
which case everybody exits anyway.

So yes, it could concievably happen, but the odds are probably well 
under 0.1%.

Cheers; Leon



More information about the plug mailing list