Re: fork and process timing issue

Jens.Toerring_at_physik.fu-berlin.de
Date: 05/28/04


Date: 28 May 2004 15:20:13 GMT

pat saunders <pat.saunders@sis.securicor.co.uk> wrote:
> 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.

Sorry, but that sentence doesn't make sense to me.

> 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.

There's no way how you can influence which process is going to be run
first (and on a multi-processor machine they may even be run at the
same time). If it "worked" before it was just by chance. If you want to
keep process B from exec-ing before process A has run for some time you
could for example install a signal handler before you fork() (e.g. for
SIGUSR1) which does nothing and then put a pause() call before the call
of execl(). Now process B will sleep until prcess A sends it a SIGUSR1
signal. That's safer than using sleep() because you can't say in advance
when process A is finished doing whatever it needs to do.

                                   Regards, Jens

-- 
  \   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
   \__________________________  http://www.toerring.de


Relevant Pages

  • 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
    ... > If I have a process A that forks() and execl() a process B. ... > switch (pid) ... Anything that just tries to "give A a timeslice" is just a probabilistic ...
    (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)
  • Re: help: exit does not exit
    ... puts "waiting for $pid" ... You probably want "exec" rather than execl. ...
    (comp.lang.tcl)