File: 022_kernel_waitpid.c

package info (click to toggle)
cowdancer 0.73
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 752 kB
  • ctags: 269
  • sloc: ansic: 3,822; sh: 481; makefile: 191; cpp: 6
file content (34 lines) | stat: -rwxr-xr-x 536 bytes parent folder | download | duplicates (2)
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
32
33
34
/*BINFMTC:
   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);
    }
}