blob: 9c1c65214ea0a35c048d6e7f6feb64a0b4a266ea [file] [log] [blame]
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +01001/*
2 * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TST_PID_H__
19#define TST_PID_H__
20
Cyril Hrubis76717402016-04-11 16:19:17 +020021#include <sys/types.h>
22
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010023/*
24 * Get a pid value not used by the OS
25 */
26pid_t tst_get_unused_pid_(void (*cleanup_fn)(void));
27
28/*
29 * Returns number of free pids by substarction of the number of pids
30 * currently used ('ps -eT') from max_pids
31 */
32int tst_get_free_pids_(void (*cleanup_fn)(void));
33
34#ifdef TST_TEST_H__
35static inline pid_t tst_get_unused_pid(void)
36{
37 return tst_get_unused_pid_(NULL);
38}
39
40static inline int tst_get_free_pids(void)
41{
42 return tst_get_free_pids_(NULL);
43}
44#else
45static inline pid_t tst_get_unused_pid(void (*cleanup_fn)(void))
46{
47 return tst_get_unused_pid_(cleanup_fn);
48}
49
50static inline int tst_get_free_pids(void (*cleanup_fn)(void))
51{
52 return tst_get_free_pids_(cleanup_fn);
53}
54#endif
55
56#endif /* TST_PID_H__ */