1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) 2022 SUSE LLC <mdoucha@suse.cz> 4 */ 5 6 /*\ 7 * Test whether the LTP library properly reaps any children left over when 8 * the main test process dies. Run using test_children_cleanup.sh. 9 */ 10 11 #include <unistd.h> 12 #include <signal.h> 13 14 #include "tst_test.h" 15 run(void)16static void run(void) 17 { 18 pid_t child_pid, main_pid = getpid(); 19 20 tst_res(TINFO, "Main process %d starting", main_pid); 21 22 /* Check that normal child reaping does not disrupt the test */ 23 if (!SAFE_FORK()) 24 return; 25 26 SAFE_WAIT(NULL); 27 child_pid = SAFE_FORK(); 28 29 /* Start child that will outlive the main test process */ 30 if (!child_pid) { 31 sleep(30); 32 return; 33 } 34 35 tst_res(TINFO, "Forked child %d", child_pid); 36 kill(main_pid, SIGKILL); 37 } 38 39 static struct tst_test test = { 40 .test_all = run, 41 .forks_child = 1, 42 }; 43