RE: Gack, this shouldn't happen under a stable OS I think

Michael Beach (mbeach@awa.com.au)
Mon, 23 Sep 1996 20:53:26 +-1000


Yes, if the grep is *running* (or rather, if the parent shell was able to run to the point where it could fork again and exec the grep, and ....); a thinko on my part.

And yes again, it's not a kernel bug, apologies if I gave the impression that I thought it was.

Regards
M.Beach

----------
From: Peter T. Breuer[SMTP:ptb@dit.upm.es]
Sent: Monday, 23 September 1996 21:08
To: Michael Beach
Cc: linux-kernel@vger.rutgers.edu
Subject: Re: Gack, this shouldn't happen under a stable OS I think

>
> Depends on the order in which the shell and the children it forks are scheduled. If the grep gets scheduled before the ps you will see it, if not, you won't.

Yes. If the grep is running when the ps reads the table, you mean ...

BUt (see below) this is NOT a kernel bug.

> Regards
> M.Beach
>
> ----------
> From: Jon Lewis[SMTP:jlewis@inorganic5.fdt.net]
> Sent: Monday, 23 September 1996 10:46
> To: Chris Fearnley
> Cc: Linus.Torvalds@helsinki.fi; alan@lxorguk.ukuu.org.uk; linux-kernel@vger.rutgers.edu
> Subject: Re: Gack, this shouldn't happen under a stable OS I think

> > root@syntropy # ps aux|grep 27231
> > root 27231 0.0 2.1 828 324 p7 S 23:28 0:00 /usr/sbin/radiusd
> > root@syntropy # ps aux|grep 27231
> > root 27231 0.0 2.1 828 324 p7 S 23:28 0:00 /usr/sbin/radiusd
> > root@syntropy # ps aux|grep 27231
> > root 27231 0.0 2.1 828 324 p7 S 23:28 0:00 /usr/sbin/radiusd
> > root 27239 0.0 2.5 916 376 p7 S 23:28 0:00 grep 27231
> >
> > Why doesn't the grep process show up each time???
>
> I've seen this sort of thing plenty of times. A better question might be
> why does the grep show up at all, or why isn't it consistant? Isn't the
> ps finished by the time grep runs?

No of course not! That's the whole point of unix. The ps and the grep
are running simultaneously - i.e. interleaving (on a uniprocessor).

If this were msdos then the ps world have to finish before the grep
could stat running, but not here. The output from the ps is produced a
bit at a time and the grep running "in parallel" reads it a bit at a
time.

For the grep to show up the ps has to be slow starting up - but this is
dependent on the shell implementation of piping and the kernel
implementation too ... and on an SMP box it really ought to be possible
for one process to finish before the other starts up and for them to
see each others stdout/stdin via the kernel. COme to that, it ought to be
possible on a uniprocessor.

Lamport's clocks article, anybody?

> ------------------------------------------------------------------
> Jon Lewis <jlewis@fdt.net> | Unsolicited commercial e-mail will
> Network Administrator | be proof-read for $199/hr.
> ________Finger jlewis@inorganic5.fdt.net for PGP public key_______

Peter T. Breuer
,---------------------------------------------------------------------------
|Departamento de Ingenieria de Sistemas Telematicos, Universidad Politecnica
|de Madrid, Escuela Tecnica Superior de Ingenieros de Telecomunicacion,
|Ciudad Universitaria, E--28040 Madrid, SPAIN.
|Tel. Office : +34 (1)336 6831
| Fax : +34 (1)543 2077 or 336 7333
|Internet : <ptb@eng.cam.ac.uk, ptb@comlab.ox.ac.uk, ptb@dit.upm.es>
| URL : http://www.dit.upm.es:80/~ptb/
`---------------------------------------------------------------------------