muimaster.library: support Listview_List in List
[AROS.git] / compiler / posixc / wait.c
blob38b84ce89742657b4dc202149c85968912755f4e
1 /*
2 Copyright © 2004-2013, 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/debug.h>
12 #include <sys/types.h>
13 #include <errno.h>
15 /*****************************************************************************
17 NAME */
18 #include <sys/wait.h>
20 pid_t wait(
22 /* SYNOPSIS */
23 int *status)
25 /* FUNCTION
26 Waits for child process to change state. State change is one of the
27 following events: child has exited, child was terminated by a signal,
28 child was stopped by a signal, child was resumed by a signal.
30 The function stores status of the process that changed state in the
31 pointer given as status argument.
33 The following macros can be used to extract information from the
34 status value:
36 WIFEXITED(status) - true if the process has exited
37 WEXITSTATUS(status) - exit status of the exited process
38 WIFSIGNALED(status) - true if the child process was terminated by a
39 signal
40 WTERMSIG(status) - number of the signal that caused process
41 termination
42 WIFSTOPPED(status) - true if the child process was stopped by a
43 signal
44 WSTOPSIG(status) - number of the signal that caused child process
45 stop
46 WIFCONTINUED(status) - true if the child process was resumed by the
47 SIGCONT signal.
49 Parent process will be suspended until a child changes state. If a
50 child process has already changed state, function returns immediately.
52 INPUTS
53 status - Pointer to int where child return status will be stored or
54 NULL if you don't want to store status.
56 RESULT
57 Process id of the child process on success or -1 on error. If an error
58 occurred, the global variable errno is set.
60 NOTES
61 This function will work only for child processeses notifying parent
62 process of their death, for example processes created by vfork() call.
63 If you want to use it for other processes, remember to set the
64 NP_NotifyOnDeath tag value to TRUE during child process creation.
66 EXAMPLE
68 BUGS
70 SEE ALSO
71 waitpid()
73 INTERNALS
74 Since POSIX signals are not yet implemented, WIFSIGNALED, WIFSTOPPED
75 and WIFCONTINUED macros always return 0. WIFEXITED always returns 1.
77 The et_UniqueID field of the ETask structure is used as process id.
79 ******************************************************************************/
81 pid_t ret = -1;
82 struct ETask *et;
84 D(bug("wait()\n"));
86 et = GetETask(FindTask(NULL));
87 if(!et)
89 /* only ETasks are fertile */
90 errno = ECHILD;
91 return -1;
94 et = (struct ETask *)ChildWait(0);
95 if (et != (struct ETask *)CHILD_NOTNEW)
97 if(status)
99 *status = et->et_Result1;
101 ret = et->et_UniqueID;
102 ChildFree(et->et_UniqueID);
104 else
105 errno = ECHILD;
107 return ret;