1 /* SPDX-License-Identifier: GPL-2.0-or-later 2 * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz> 3 */ 4 5 #ifndef TST_PID_H__ 6 #define TST_PID_H__ 7 8 #include <sys/types.h> 9 10 /* 11 * Get a pid value not used by the OS 12 */ 13 pid_t tst_get_unused_pid_(void (*cleanup_fn)(void)); 14 15 /* 16 * Returns number of free pids by subtraction of the number of pids 17 * currently used ('ps -eT') from maximum number of processes. 18 * The limit of processes come from kernel pid_max and cgroup session limits 19 * (e.g. configured by systemd user.slice). 20 */ 21 int tst_get_free_pids_(void (*cleanup_fn)(void)); 22 23 #ifdef TST_TEST_H__ tst_get_unused_pid(void)24static inline pid_t tst_get_unused_pid(void) 25 { 26 return tst_get_unused_pid_(NULL); 27 } 28 tst_get_free_pids(void)29static inline int tst_get_free_pids(void) 30 { 31 return tst_get_free_pids_(NULL); 32 } 33 #else tst_get_unused_pid(void (* cleanup_fn)(void))34static inline pid_t tst_get_unused_pid(void (*cleanup_fn)(void)) 35 { 36 return tst_get_unused_pid_(cleanup_fn); 37 } 38 tst_get_free_pids(void (* cleanup_fn)(void))39static inline int tst_get_free_pids(void (*cleanup_fn)(void)) 40 { 41 return tst_get_free_pids_(cleanup_fn); 42 } 43 #endif 44 45 #endif /* TST_PID_H__ */ 46