File: 022_kernel_waitpid.c

package info (click to toggle)
cowdancer 0.47
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 696 kB
  • ctags: 179
  • sloc: ansic: 2,634; sh: 407; makefile: 116; cpp: 6; python: 4
file content (35 lines) | stat: -rwxr-xr-x 547 bytes parent folder | download | duplicates (4)
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
35
/*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);
    }
  
}