[comp.unix.questions] How to get Status of processes in C environment

jian@kuhub.cc.ukans.edu (09/08/90)

How does a program know the status of its spawned processes in C environment?
In other words, what system calls can I use to get the status of spawned
processes? Thanks in advance.

Jian Q. Li
jian@kuhub.cc.ukans.edu

luj@delta.ecn.purdue.edu (Jun Lu) (09/09/90)

In article <25467.26e7ac6a@kuhub.cc.ukans.edu> jian@kuhub.cc.ukans.edu writes:
>How does a program know the status of its spawned processes in C environment?
>In other words, what system calls can I use to get the status of spawned
>processes? Thanks in advance.
>
Try wait(2). Note the arg to the sys call is different on a BSD and SysV.
For more info, type "man 2 wait".

--
-------------------------------------------------------------------------------
   Jun Lu, School of Aero & Astro, Purdue University, W. Lafayette, IN 47907
Internet:luj@ecn.purdue.edu  Bitnet:luj%ecn.purdue.edu@purccvm  UUCP:pur-ee!luj
          Phone: 317-494-7864          Fax: 317-494-0307

guy@auspex.auspex.com (Guy Harris) (09/12/90)

>Try wait(2). Note the arg to the sys call is different on a BSD and SysV.

Actually, from the kernel's standpoint, the argument is the *same* in
BSD and other systems.  Some excessively-helpful person at Berkeley
created "union wait" as a *user-mode* wrapper around the "int" that the
underlying implementation of "wait()", in most if not all UNIX systems,
returns.

If you just ignore "union wait" (and the "lint" complaints that doing so
will give you), and treat the "status" argument to "wait()" as an "int
*", even on BSD systems, your code will still work (unless the
implementor of your UNIX system screwed up badly), but will be more
portable and won't be polluted with #ifdefs. 

chris@mimsy.umd.edu (Chris Torek) (09/12/90)

In article <4049@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
>If you just ignore "union wait" (and the "lint" complaints that doing so
>will give you), and treat the "status" argument to "wait()" as an "int
>*", even on BSD systems, your code will still work (unless the
>implementor of your UNIX system screwed up badly), but will be more
>portable and won't be polluted with #ifdefs. 

Right.

Note, in 4.3BSD-reno the argument to wait (and wait3) has been changed
back to `int *'.  The W* macros in <sys/wait.h> operate on `int' lvalues
(and continue to work on `union wait's by the bletcherous hack of
defining the W* macros as, e.g.,

	#define _W_INT(w)	(*(int *)&(w))
	#define	WEXITSTATUS(x)	(_W_INT(x) >> 8)

The funny _W_INT definition WILL GO AWAY someday, along with `union wait'.)
If compiling with the (semi-nonexistent) `POSIX compiler', the W* macros
operate on int expressions (because _W_INT(w) is defined is (w)).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris