Upgraded GRUB2 to 2.00 release.
[AROS.git] / compiler / clib / wait.c
blob04e004736e2d33b7fe0f77d3b21e2cbfc0d11935
1 /*
2 Copyright © 2004-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <aros/debug.h>
9 #include <proto/exec.h>
10 #include <aros/startup.h>
11 #include <aros/debug.h>
13 #include "__arosc_privdata.h"
15 #include <sys/types.h>
16 #include <errno.h>
18 /*****************************************************************************
20 NAME */
21 #include <sys/wait.h>
23 pid_t wait(
25 /* SYNOPSIS */
26 int *status)
28 /* FUNCTION
29 Waits for child process to change state. State change is one of the
30 following events: child has exited, child was terminated by a signal,
31 child was stopped by a signal, child was resumed by a signal.
33 The function stores status of the process that changed state in the
34 pointer given as status argument.
36 The following macros can be used to extract information from the
37 status value:
39 WIFEXITED(status) - true if the process has exited
40 WEXITSTATUS(status) - exit status of the exited process
41 WIFSIGNALED(status) - true if the child process was terminated by a
42 signal
43 WTERMSIG(status) - number of the signal that caused process
44 termination
45 WIFSTOPPED(status) - true if the child process was stopped by a
46 signal
47 WSTOPSIG(status) - number of the signal that caused child process
48 stop
49 WIFCONTINUED(status) - true if the child process was resumed by the
50 SIGCONT signal.
52 Parent process will be suspended until a child changes state. If a
53 child process has already changed state, function returns immediately.
55 INPUTS
56 status - Pointer to int where child return status will be stored or
57 NULL if you don't want to store status.
59 RESULT
60 Process id of the child process on success or -1 on error. If an error
61 occurred, the global variable errno is set.
63 NOTES
64 This function will work only for child processeses notifying parent
65 process of their death, for example processes created by vfork() call.
66 If you want to use it for other processes, remember to set the
67 NP_NotifyOnDeath tag value to TRUE during child process creation.
69 EXAMPLE
71 BUGS
73 SEE ALSO
74 waitpid()
76 INTERNALS
77 Since POSIX signals are not yet implemented, WIFSIGNALED, WIFSTOPPED
78 and WIFCONTINUED macros always return 0. WIFEXITED always returns 1.
80 The et_UniqueID field of the ETask structure is used as process id.
82 ******************************************************************************/
84 pid_t ret = -1;
85 struct ETask *et;
87 D(bug("wait()\n"));
89 et = GetETask(FindTask(NULL));
90 if(!et)
92 /* only ETasks are fertile */
93 errno = ECHILD;
94 return -1;
97 et = (struct ETask *)ChildWait(0);
98 if (et != (struct ETask *)CHILD_NOTNEW)
100 if(status)
102 *status = et->et_Result1;
104 ret = et->et_UniqueID;
105 ChildFree(et->et_UniqueID);
107 else
108 errno = ECHILD;
110 return ret;