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