File: 022_kernel_waitpid.c

package info (click to toggle)
cowdancer 0.90
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 648 kB
  • sloc: ansic: 4,593; sh: 407; makefile: 142; cpp: 5
file content (31 lines) | stat: -rw-r--r-- 494 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
   test that waitpid works expected way
 */
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main() {
	pid_t pid;
	int status;

	switch (pid = fork()) {
		case 0:
			execl("/bin/cp", "/bin/cp", "-a", "/tmp/test", "/tmp/test2", NULL);
			exit(0);

		case -1:
			perror("fork()");
			exit(1);

		default:
			sleep(1);
			if (-1 == waitpid(pid, &status, 0)) {
				perror("waitpid:cp");
				exit(2);
			}
			printf("waitpid: %x\n", status);
			exit(0);
	}
}