• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright (C) 2012-2014 Cyril Hrubis chrubis@suse.cz
3  */
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
9    blocks.
10 
11   */
12 
13 #ifndef TST_PROCESS_STATE__
14 #define TST_PROCESS_STATE__
15 
16 #include <unistd.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 #ifdef TST_TEST_H__
30 
31 #define TST_PROCESS_STATE_WAIT(pid, state, msec_timeout) \
32 	tst_process_state_wait(__FILE__, __LINE__, NULL, \
33 	                       (pid), (state), (msec_timeout))
34 #else
35 /*
36  * The same as above but does not use tst_brkm() interface.
37  *
38  * This function is intended to be used from child processes.
39  *
40  * Returns zero on success, non-zero on failure.
41  */
42 int tst_process_state_wait2(pid_t pid, const char state);
43 
44 # define TST_PROCESS_STATE_WAIT(cleanup_fn, pid, state) \
45 	 tst_process_state_wait(__FILE__, __LINE__, (cleanup_fn), \
46 	                        (pid), (state), 0)
47 #endif
48 
49 int tst_process_state_wait(const char *file, const int lineno,
50                             void (*cleanup_fn)(void), pid_t pid,
51 			    const char state, unsigned int msec_timeout);
52 
53 #endif /* TST_PROCESS_STATE__ */
54