arch/m68k-amiga: Define the gcc symbol 'start' instead of using .bss
[AROS.git] / compiler / clib / wait.c
blobd10d7c2bdc6faf40109d5cbdc9a3a8b6a5f3252e
1 /*
2 Copyright © 2004-2009, 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 "etask.h"
14 #include "__arosc_privdata.h"
16 #include <sys/types.h>
17 #include <sys/wait.h>
18 #include <errno.h>
20 /*****************************************************************************
22 NAME */
24 pid_t wait(
26 /* SYNOPSIS */
27 int *status)
29 /* FUNCTION
30 Waits for child process to change state. State change is one of the
31 following events: child has exited, child was terminated by a signal,
32 child was stopped by a signal, child was resumed by a signal.
34 The function stores status of the process that changed state in the
35 pointer given as status argument.
37 The following macros can be used to extract information from the
38 status value:
40 WIFEXITED(status) - true if the process has exited
41 WEXITSTATUS(status) - exit status of the exited process
42 WIFSIGNALED(status) - true if the child process was terminated by a
43 signal
44 WTERMSIG(status) - number of the signal that caused process
45 termination
46 WIFSTOPPED(status) - true if the child process was stopped by a
47 signal
48 WSTOPSIG(status) - number of the signal that caused child process
49 stop
50 WIFCONTINUED(status) - true if the child process was resumed by the
51 SIGCONT signal.
53 Parent process will be suspended until a child changes state. If a
54 child process has already changed state, function returns immediately.
56 INPUTS
57 status - Pointer to int where child return status will be stored or
58 NULL if you don't want to store status.
60 RESULT
61 Process id of the child process on success or -1 on error. If an error
62 occurred, the global variable errno is set.
64 NOTES
65 This function will work only for child processeses notifying parent
66 process of their death, for example processes created by vfork() call.
67 If you want to use it for other processes, remember to set the
68 NP_NotifyOnDeath tag value to TRUE during child process creation.
70 EXAMPLE
72 BUGS
74 SEE ALSO
75 waitpid()
77 INTERNALS
78 Since POSIX signals are not yet implemented, WIFSIGNALED, WIFSTOPPED
79 and WIFCONTINUED macros always return 0. WIFEXITED always returns 1.
81 The et_UniqueID field of the ETask structure is used as process id.
83 ******************************************************************************/
85 pid_t ret = -1;
86 struct ETask *et;
88 D(bug("wait()\n"));
90 et = GetETask(FindTask(NULL));
91 if(!et)
93 /* only ETasks are fertile */
94 errno = ECHILD;
95 return -1;
98 et = (struct ETask *)ChildWait(0);
99 if (et != (struct ETask *)CHILD_NOTNEW)
101 if(status)
103 *status = et->et_Result1;
105 ret = et->et_UniqueID;
106 ChildFree(et->et_UniqueID);
108 else
109 errno = ECHILD;
111 return ret;