1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later 2*49cdfc7eSAndroid Build Coastguard Worker /* 3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001 4*49cdfc7eSAndroid Build Coastguard Worker */ 5*49cdfc7eSAndroid Build Coastguard Worker 6*49cdfc7eSAndroid Build Coastguard Worker /*\ 7*49cdfc7eSAndroid Build Coastguard Worker * [Description] 8*49cdfc7eSAndroid Build Coastguard Worker * 9*49cdfc7eSAndroid Build Coastguard Worker * Check that getppid() in child returns the same pid as getpid() in parent. 10*49cdfc7eSAndroid Build Coastguard Worker */ 11*49cdfc7eSAndroid Build Coastguard Worker 12*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h> 13*49cdfc7eSAndroid Build Coastguard Worker 14*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h" 15*49cdfc7eSAndroid Build Coastguard Worker verify_getppid(void)16*49cdfc7eSAndroid Build Coastguard Workerstatic void verify_getppid(void) 17*49cdfc7eSAndroid Build Coastguard Worker { 18*49cdfc7eSAndroid Build Coastguard Worker pid_t proc_id; 19*49cdfc7eSAndroid Build Coastguard Worker pid_t pid; 20*49cdfc7eSAndroid Build Coastguard Worker pid_t pproc_id; 21*49cdfc7eSAndroid Build Coastguard Worker 22*49cdfc7eSAndroid Build Coastguard Worker proc_id = getpid(); 23*49cdfc7eSAndroid Build Coastguard Worker pid = SAFE_FORK(); 24*49cdfc7eSAndroid Build Coastguard Worker if (pid == 0) { 25*49cdfc7eSAndroid Build Coastguard Worker pproc_id = getppid(); 26*49cdfc7eSAndroid Build Coastguard Worker 27*49cdfc7eSAndroid Build Coastguard Worker if (pproc_id != proc_id) 28*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL, "child's ppid(%d) not equal to parent's pid(%d)", 29*49cdfc7eSAndroid Build Coastguard Worker pproc_id, proc_id); 30*49cdfc7eSAndroid Build Coastguard Worker else 31*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "getppid() returned parent pid (%d)", proc_id); 32*49cdfc7eSAndroid Build Coastguard Worker } 33*49cdfc7eSAndroid Build Coastguard Worker } 34*49cdfc7eSAndroid Build Coastguard Worker 35*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = { 36*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1, 37*49cdfc7eSAndroid Build Coastguard Worker .test_all = verify_getppid, 38*49cdfc7eSAndroid Build Coastguard Worker }; 39