FreeNOS
waitpid.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <FreeNOS/User.h>
19 #include "sys/wait.h"
20 #include "sys/types.h"
21 #include <errno.h>
22 
23 pid_t waitpid(pid_t pid, int *stat_loc, int options)
24 {
25  const ulong result = (ulong) ProcessCtl(pid, WaitPID);
26 
27  switch ((const API::Result) (result & 0xffff))
28  {
29  case API::NotFound:
30  errno = ESRCH;
31  return (pid_t) -1;
32 
33  case API::Success:
34  if (stat_loc)
35  {
36  *stat_loc = result >> 16;
37  }
38  return pid;
39 
40  default:
41  errno = EIO;
42  return (pid_t) -1;
43  }
44 }
API::Result
Result
Enumeration of generic kernel API result codes.
Definition: API.h:68
ulong
unsigned long ulong
Unsigned long number.
Definition: Types.h:47
errno
C int errno
The lvalue errno is used by many functions to return error values.
types.h
ProcessCtl
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
Definition: ProcessCtl.h:93
wait.h
WaitPID
@ WaitPID
Definition: ProcessCtl.h:48
EIO
#define EIO
I/O error.
Definition: errno.h:130
ESRCH
#define ESRCH
No such process.
Definition: errno.h:268
pid_t
ProcessID pid_t
Used for process IDs and process group IDs.
Definition: types.h:32
API::NotFound
@ NotFound
Definition: API.h:73
API::Success
@ Success
Definition: API.h:70
waitpid
pid_t waitpid(pid_t pid, int *stat_loc, int options)
Wait for a child process to stop or terminate.
Definition: waitpid.cpp:23
errno.h