• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  */
5 
6 /*\
7  * [Description]
8  *
9  * Verify that getpid() system call returns process ID in range 2 ... PID_MAX
10  */
11 
12 #include <stdlib.h>
13 #include "tst_test.h"
14 
verify_getpid(void)15 static void verify_getpid(void)
16 {
17 	pid_t pid_max, pid;
18 	int i;
19 
20 	SAFE_FILE_SCANF("/proc/sys/kernel/pid_max", "%d\n", &pid_max);
21 
22 	for (i = 0; i < 100; i++) {
23 		pid = SAFE_FORK();
24 		if (pid == 0) {
25 			pid = getpid();
26 
27 			/* pid should not be 1 or out of maximum */
28 			if (1 < pid && pid <= pid_max)
29 				tst_res(TPASS, "getpid() returns %d", pid);
30 			else
31 				tst_res(TFAIL,
32 					"getpid() returns out of range: %d", pid);
33 			exit(0);
34 		} else {
35 			SAFE_WAIT(NULL);
36 		}
37 	}
38 }
39 
40 static struct tst_test test = {
41 	.forks_child = 1,
42 	.test_all = verify_getpid,
43 };
44