xref: /llvm-project/lldb/test/Shell/Commands/Inputs/sigchld.c (revision 287ce6b51675aee43870bebfff68bb144d1ab90e)
1*287ce6b5SMichał Górny #include <assert.h>
2*287ce6b5SMichał Górny #include <signal.h>
3*287ce6b5SMichał Górny #include <stdio.h>
4*287ce6b5SMichał Górny #include <unistd.h>
5*287ce6b5SMichał Górny #include <sys/wait.h>
6*287ce6b5SMichał Górny 
handler(int signo)7*287ce6b5SMichał Górny void handler(int signo) {
8*287ce6b5SMichał Górny   printf("SIGCHLD\n");
9*287ce6b5SMichał Górny }
10*287ce6b5SMichał Górny 
main()11*287ce6b5SMichał Górny int main() {
12*287ce6b5SMichał Górny   void *ret = signal(SIGINT, handler);
13*287ce6b5SMichał Górny   assert (ret != SIG_ERR);
14*287ce6b5SMichał Górny 
15*287ce6b5SMichał Górny   pid_t child_pid = fork();
16*287ce6b5SMichał Górny   assert (child_pid != -1);
17*287ce6b5SMichał Górny 
18*287ce6b5SMichał Górny   if (child_pid == 0) {
19*287ce6b5SMichał Górny     sleep(1);
20*287ce6b5SMichał Górny     _exit(14);
21*287ce6b5SMichał Górny   }
22*287ce6b5SMichał Górny 
23*287ce6b5SMichał Górny   printf("signo = %d\n", SIGCHLD);
24*287ce6b5SMichał Górny   printf("code = %d\n", CLD_EXITED);
25*287ce6b5SMichał Górny   printf("child_pid = %d\n", child_pid);
26*287ce6b5SMichał Górny   printf("uid = %d\n", getuid());
27*287ce6b5SMichał Górny   pid_t waited = wait(NULL);
28*287ce6b5SMichał Górny   assert(waited == child_pid);
29*287ce6b5SMichał Górny 
30*287ce6b5SMichał Górny   return 0;
31*287ce6b5SMichał Górny }
32