Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 1 | /* |
| 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 Hrubis | 7671740 | 2016-04-11 16:19:17 +0200 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 23 | /* |
| 24 | * Get a pid value not used by the OS |
| 25 | */ |
| 26 | pid_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 | */ |
| 32 | int tst_get_free_pids_(void (*cleanup_fn)(void)); |
| 33 | |
| 34 | #ifdef TST_TEST_H__ |
| 35 | static inline pid_t tst_get_unused_pid(void) |
| 36 | { |
| 37 | return tst_get_unused_pid_(NULL); |
| 38 | } |
| 39 | |
| 40 | static inline int tst_get_free_pids(void) |
| 41 | { |
| 42 | return tst_get_free_pids_(NULL); |
| 43 | } |
| 44 | #else |
| 45 | static inline pid_t tst_get_unused_pid(void (*cleanup_fn)(void)) |
| 46 | { |
| 47 | return tst_get_unused_pid_(cleanup_fn); |
| 48 | } |
| 49 | |
| 50 | static 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__ */ |