1 /* 2 * Copyright (C) 2012-2014 Cyril Hrubis chrubis@suse.cz 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it would be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * Further, this software is distributed without any warranty that it is 13 * free of the rightful claim of any third person regarding infringement 14 * or the like. Any license provided herein, whether implied or 15 * otherwise, applies only to this software file. Patent licenses, if 16 * any, provided herein do not apply to combinations of this program with 17 * other software, or any other product whatsoever. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write the Free Software Foundation, Inc., 21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 */ 23 24 /* 25 26 These functions helps you wait till a process with given pid changes state. 27 This is for example useful when you need to wait in parent until child 28 blocks. 29 30 */ 31 32 #ifndef TST_PROCESS_STATE__ 33 #define TST_PROCESS_STATE__ 34 35 #include <unistd.h> 36 37 /* 38 * Waits for process state change. 39 * 40 * The state is one of the following: 41 * 42 * R - process is running 43 * S - process is sleeping 44 * D - process sleeping uninterruptibly 45 * Z - zombie process 46 * T - process is traced 47 */ 48 #ifdef TST_TEST_H__ 49 50 #define TST_PROCESS_STATE_WAIT(pid, state) \ 51 tst_process_state_wait(__FILE__, __LINE__, NULL, \ 52 (pid), (state)) 53 #else 54 /* 55 * The same as above but does not use tst_brkm() interface. 56 * 57 * This function is intended to be used from child processes. 58 * 59 * Returns zero on success, non-zero on failure. 60 */ 61 int tst_process_state_wait2(pid_t pid, const char state); 62 63 # define TST_PROCESS_STATE_WAIT(cleanup_fn, pid, state) \ 64 tst_process_state_wait(__FILE__, __LINE__, (cleanup_fn), \ 65 (pid), (state)) 66 #endif 67 68 void tst_process_state_wait(const char *file, const int lineno, 69 void (*cleanup_fn)(void), 70 pid_t pid, const char state); 71 72 #endif /* TST_PROCESS_STATE__ */ 73