brintos

brintos / llvm-project-archived public Read only

0
0
Text · 649 B · 0121e70 Raw
36 lines · c
1#if defined(__linux__)2#define _XOPEN_SOURCE 500 /* for CLD_EXITED */3#endif4 5#include <assert.h>6#include <signal.h>7#include <stdio.h>8#include <unistd.h>9#include <sys/wait.h>10 11void handler(int signo) {12  printf("SIGCHLD\n");13}14 15int main() {16  void *ret = signal(SIGINT, handler);17  assert (ret != SIG_ERR);18 19  pid_t child_pid = fork();20  assert (child_pid != -1);21 22  if (child_pid == 0) {23    sleep(1);24    _exit(14);25  }26 27  printf("signo = %d\n", SIGCHLD);28  printf("code = %d\n", CLD_EXITED);29  printf("child_pid = %d\n", child_pid);30  printf("uid = %d\n", getuid());31  pid_t waited = wait(NULL);32  assert(waited == child_pid);33 34  return 0;35}36