1 ;;; This is a "repear" program that merely waits for child processes
2 ;;; to appear and "reap" them, i.e. read their exit status to let them
3 ;;; exit. The program allows an arbitrary first argument that is
4 ;;; indended for identifying the reaper process.
6 format elf64 executable
9 ;;; Using mixed Data and Code segment for size squeeze
11 segment readable writable executable
15 ;; if (getpid() != 1) exit 1;
24 ;; Continue here for pid 1 only
27 ;; sigprocmask(SIG_BLOCK, &set, 0);
29 mov rdi, rax ; SIG_BLOCK = 0
33 mov al, 14 ; sys_rt_sigprocmask
34 ; rax=14, rdi=0, rsi=[set], rdx=0, r10=0
37 ;; loop waiting for children, and reading their exit status
39 ;; first clear status area again
45 mov cl, status$end-status
48 ;; waitid( idtype, id, *status, options )
49 mov rdi, rax ; idtype_t idtype = P_ALL = 0
50 mov rsi, rax ; int id = 0
51 ;rdx = [status] ; siginfo_t* = &status
52 mov al, 4 ; int options = WEXITED = 4
55 ; rax=247, rdi=0, rsi=0, rdx=[status], r10=4
58 add rax, 10 ; -10 = ECHILD (no child processes)
66 syscall ; exit(1) program
68 ;; sigset_t set -- bit mask for sigprocmask
72 ;;; siginfo_t status -- all ignored