1 /* SPDX-License-Identifier: GPL-2.0-or-later 2 * Copyright (C) 2012-2014 Cyril Hrubis chrubis@suse.cz 3 * Copyright (C) 2021 Xie Ziyao <xieziyao@huawei.com> 4 */ 5 6 /* 7 * These functions helps you wait till a process with given pid changes state. 8 * This is for example useful when you need to wait in parent until child blocks. 9 */ 10 11 #ifndef TST_PROCESS_STATE__ 12 #define TST_PROCESS_STATE__ 13 14 #include <unistd.h> 15 16 #ifdef TST_TEST_H__ 17 18 /* 19 * Waits for process state change. 20 * 21 * The state is one of the following: 22 * 23 * R - process is running 24 * S - process is sleeping 25 * D - process sleeping uninterruptibly 26 * Z - zombie process 27 * T - process is traced 28 */ 29 #define TST_PROCESS_STATE_WAIT(pid, state, msec_timeout) \ 30 tst_process_state_wait(__FILE__, __LINE__, NULL, \ 31 (pid), (state), (msec_timeout)) 32 33 /* 34 * Check that a given pid is present on the system 35 */ 36 #define TST_PROCESS_EXIT_WAIT(pid, msec_timeout) \ 37 tst_process_exit_wait((pid), (msec_timeout)) 38 39 #else 40 /* 41 * The same as above but does not use tst_brkm() interface. 42 * 43 * This function is intended to be used from child processes. 44 * 45 * Returns zero on success, non-zero on failure. 46 */ 47 int tst_process_state_wait2(pid_t pid, const char state); 48 49 #define TST_PROCESS_STATE_WAIT(cleanup_fn, pid, state) \ 50 tst_process_state_wait(__FILE__, __LINE__, (cleanup_fn), \ 51 (pid), (state), 0) 52 #endif 53 54 int tst_process_state_wait(const char *file, const int lineno, 55 void (*cleanup_fn)(void), pid_t pid, 56 const char state, unsigned int msec_timeout); 57 int tst_process_exit_wait(pid_t pid, unsigned int msec_timeout); 58 59 #endif /* TST_PROCESS_STATE__ */ 60