File: waitpid.c

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (32 lines) | stat: -rw-r--r-- 693 bytes parent folder | download
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
#include <libgen.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>

int main ( int argc, char** argv )
{
    int childpid = fork();
    if ( childpid == 0 ) { /* if child */
      char *newargv[3];

      char dmtcp1Path[4096];
      strcpy (dmtcp1Path, argv[0]);
      dirname(dmtcp1Path);
      strcat(dmtcp1Path, "/dmtcp1");

      /* sleep for a long time */
      newargv[0] = "dmtcp1";
      newargv[1] = "100";
      newargv[2] = NULL;
      execv (dmtcp1Path, newargv);
      perror ( "execv");
    } else {
      int rc;
      rc = waitpid(childpid, NULL, 0);
      if (rc == -1)
        perror("waitpid");
    }
  return 0;
}