xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/waitid/waitid11.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Crackerjack Project., 2007
4  * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
5  */
6 
7 /*\
8  * [Description]
9  *
10  * This test is checking if waitid() syscall recognizes a process that has been
11  * killed with SIGKILL.
12  */
13 
14 #include <time.h>
15 #include <stdlib.h>
16 #include <sys/wait.h>
17 #include "tst_test.h"
18 
19 static siginfo_t *infop;
20 
run(void)21 static void run(void)
22 {
23 	pid_t pidchild;
24 
25 	pidchild = SAFE_FORK();
26 	if (!pidchild) {
27 		pause();
28 		return;
29 	}
30 
31 	SAFE_KILL(pidchild, SIGKILL);
32 
33 	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
34 	TST_EXP_EQ_LI(infop->si_pid, pidchild);
35 	TST_EXP_EQ_LI(infop->si_status, SIGKILL);
36 	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
37 	TST_EXP_EQ_LI(infop->si_code, CLD_KILLED);
38 }
39 
40 static struct tst_test test = {
41 	.test_all = run,
42 	.forks_child = 1,
43 	.bufs =	(struct tst_buffers[]) {
44 		{&infop, .size = sizeof(*infop)},
45 		{},
46 	},
47 };
48