2 Copyright © 2004-2009, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <proto/exec.h>
10 #include <exec/lists.h>
11 #include <aros/startup.h>
13 #include <sys/types.h>
18 #include "__arosc_privdata.h"
20 /*****************************************************************************
32 Waits for child process with given process id to change state. State
33 change is one of the following events: child has exited, child was
34 terminated by a signal, child was stopped by a signal, child was
37 The function stores status of the process that changed state in the
38 pointer given as status argument.
40 The following macros can be used to extract information from the
43 WIFEXITED(status) - true if the process has exited
44 WEXITSTATUS(status) - exit status of the exited process
45 WIFSIGNALED(status) - true if the child process was terminated by a
47 WTERMSIG(status) - number of the signal that caused process
49 WIFSTOPPED(status) - true if the child process was stopped by a
51 WSTOPSIG(status) - number of the signal that caused child process
53 WIFCONTINUED(status) - true if the child process was resumed by the
56 Unless WNOHANG option is set, parent process will be suspended until a
57 child changes state. If a child process has already changed state,
58 function returns immediately.
61 pid - Process id of the process you want to wait for or -1 to wait for
63 status - Pointer to int where child status will be stored or NULL if
64 you don't want to store status.
65 options - ORed zero or more of the following constants:
67 WNOHANG - return immediately if no child process changed state
70 Process id of the child process on success or -1 on error. If an error
71 occurred, the global variable errno is set.
74 This function will work only for child processeses notifying parent
75 process of their death, for example processes created by vfork() call.
76 If you want to use it for other processes, remember to set the
77 NP_NotifyOnDeath tag value to TRUE during child process creation.
87 Since POSIX signals are not yet implemented, WIFSIGNALED, WIFSTOPPED
88 and WIFCONTINUED macros always return 0. WIFEXITED always returns 1.
90 The et_UniqueID field of the ETask structure is used as process id.
92 ******************************************************************************/
99 D(bug("waitpid(%d, %p, %d)\n", pid
, status
, options
));
101 et
= GetETask(FindTask(NULL
));
104 /* only ETasks are fertile */
109 if (pid
< -1 || pid
== 0)
111 /* process groups not yet supported */
119 if(tid
!= 0 && ChildStatus(tid
) == CHILD_NOTFOUND
)
121 /* error if there's no such child */
126 if (options
& ~WNOHANG
)
128 /* option not yet supported */
133 /* not very pretty, perhaps we need a function for counting dead
135 ListLength(&et
->et_TaskMsgPort
.mp_MsgList
, exchildno
);
136 if ((options
& WNOHANG
) && (
137 (tid
!= 0 && ChildStatus(tid
) != CHILD_EXITED
) ||
138 (tid
== 0 && exchildno
== 0)
141 D(bug("waitpid: no dead children\n"));
142 /* no dead children atm */
146 et
= (struct ETask
*)ChildWait(tid
);
147 if (et
!= (struct ETask
*)CHILD_NOTNEW
)
151 *status
= et
->et_Result1
;
153 ret
= et
->et_UniqueID
;
154 ChildFree(et
->et_UniqueID
);
159 D(bug("waitpid: leaving (%d)\n", ret
));