Ticket #360: test.c

File test.c, 752 bytes (added by dmik, 8 years ago)
Line 
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <sys/wait.h>
6#include <fcntl.h>
7
8int main(void)
9{
10  int rc;
11  int fd;
12  int status;
13
14  pid_t pid = fork();
15  if (pid == -1)
16  {
17    perror("fork failed");
18    return 1;
19  }
20
21  if (pid == 0)
22  {
23    /* Child */
24
25    char tmp[] = "/tmp/tst-urpo-XXXXXX";
26    fd = mkstemp(tmp);
27//    fd = open(tmp, O_CREAT | O_WRONLY);
28    printf("tmp [%s] fd %d\n", tmp, fd);
29
30//    close(fd);
31//    unlink(tmp);
32
33    exit(0);
34  }
35
36  /* Parent */
37
38  if (waitpid(pid, &status, 0) != pid)
39  {
40    perror("waitpid failed");
41    return 1;
42  }
43
44  if (!WIFEXITED(status) || WEXITSTATUS(status))
45  {
46    puts("child 1 terminated abnormally or with error");
47    return 1;
48  }
49
50  return 0;
51}