Re: fork and process timing issue

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 05/28/04


Date: Fri, 28 May 2004 11:29:46 -0400

In article <bc0e3bd8.0405280650.d704260@posting.google.com>,
 pat.saunders@sis.securicor.co.uk (pat saunders) wrote:

> Hi,
> I am using c , unix (solaris 8) on a sun box, although question is a general
> one.
> If I have a process A that forks() and execl() a process B.
>
> pid = fork()
> switch (pid)
> case 0:
> execl (process B)
> case -1:
> error
> default:
> store pid in array
> continue with process A.
>
> This worked fine until upgraded h/w to a faster machine.
> Now, process A executes process B and process B executes alot of code before
> it tries to access its PID which process A has not had a chance to store due
> to
> no further time slices.
> My question is to avoid semphores etc, What commands can be used to force the
> processor to hand back a time slice to process A.
> Is sleep() the best option in process B.

If you want to ensure that processes run in a particular order, you
should use an explicit mutual exclusion mechanism, like a semaphore.
Anything that just tries to "give A a timeslice" is just a probabilistic
mechanism, and can result in intermittent failures when the timeslice it
gets isn't long enough.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages

  • Re: fork and process timing issue
    ... > If I have a process A that forks() and execl() a process B. ... > store pid in array ... > to no further time slices. ...
    (comp.unix.programmer)
  • fork and process timing issue
    ... If I have a process A that forks() and execla process B. ... switch (pid) ... process A executes process B and process B executes alot of code before ... no further time slices. ...
    (comp.unix.programmer)
  • Re: fork and process timing issue
    ... pat saunders wrote: ... > If I have a process A that forks() and execl() a process B. ... > switch (pid) ...
    (comp.unix.programmer)
  • Problems forking -- fork DOSes my comp
    ... I am learning about forks, so I tried the following code to make sure I ... use strict; ... use warnings; ... my $pid = 0; ...
    (perl.beginners)
  • Re: help: exit does not exit
    ... puts "waiting for $pid" ... You probably want "exec" rather than execl. ...
    (comp.lang.tcl)