1 /* libc/sys/linux/process.c - Process-related system calls */
2 
3 /* Written 2000 by Werner Almesberger */
4 
5 
6 #include <sys/unistd.h>
7 #include <sys/wait.h>
8 #include <machine/syscall.h>
9 
10 
11 #define __NR__exit __NR_exit
12 #define __NR__execve __NR_execve
13 
14 _syscall0(int,getpid)
15 _syscall0(pid_t,getppid)
16 
17 weak_alias(__libc_getpid,__getpid);
18 
19 #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 3
_syscall3(int,_execve,const char *,file,char * const *,argv,char * const *,envp)20 _syscall3(int,_execve,const char *,file,char * const *,argv,char * const *,envp)
21 _syscall0(int,fork)
22 #endif /* _ELIX_LEVEL >= 3 */
23 
24 #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 4
25 _syscall0(pid_t,getpgrp)
26 _syscall2(int,setpgid,pid_t,pid,pid_t,pgid)
27 _syscall0(pid_t,setsid)
28 
29 /* Here we implement vfork in terms of fork, since
30  * Linux's vfork system call is not reliable.
31  */
32 pid_t vfork(void)
33 {
34   pid_t pid;
35 
36   pid = fork();
37 
38   if(!pid)
39     {
40       /* In child. */
41       return 0;
42     }
43   else
44     {
45       /* In parent.  Wait for child to finish. */
46       if (waitpid (pid, NULL, 0) < 0)
47         return pid;
48     }
49 }
50 #endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 4 */
51 
52 
53 /* Although _exit is listed as level 3, we use it from level 1 interfaces */
54 /* FIXME: get rid of noreturn warning */
55 
56 #define return for (;;)
57 _syscall1(void,_exit,int,exitcode)
58 #undef return
59