xref: /aosp_15_r20/external/ltp/lib/tst_sig_proc.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2016 Linux Test Project
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
7*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
8*49cdfc7eSAndroid Build Coastguard Worker 
9*49cdfc7eSAndroid Build Coastguard Worker #include "tst_sig_proc.h"
10*49cdfc7eSAndroid Build Coastguard Worker 
11*49cdfc7eSAndroid Build Coastguard Worker #define TST_NO_DEFAULT_MAIN
12*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
13*49cdfc7eSAndroid Build Coastguard Worker 
create_sig_proc(int sig,int count,unsigned int usec)14*49cdfc7eSAndroid Build Coastguard Worker pid_t create_sig_proc(int sig, int count, unsigned int usec)
15*49cdfc7eSAndroid Build Coastguard Worker {
16*49cdfc7eSAndroid Build Coastguard Worker 	pid_t pid, cpid;
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker 	pid = getpid();
19*49cdfc7eSAndroid Build Coastguard Worker 	cpid = SAFE_FORK();
20*49cdfc7eSAndroid Build Coastguard Worker 
21*49cdfc7eSAndroid Build Coastguard Worker 	if (cpid == 0) {
22*49cdfc7eSAndroid Build Coastguard Worker 		while (count-- > 0) {
23*49cdfc7eSAndroid Build Coastguard Worker 			usleep(usec);
24*49cdfc7eSAndroid Build Coastguard Worker 			if (kill(pid, sig) == -1)
25*49cdfc7eSAndroid Build Coastguard Worker 				break;
26*49cdfc7eSAndroid Build Coastguard Worker 		}
27*49cdfc7eSAndroid Build Coastguard Worker 		exit(0);
28*49cdfc7eSAndroid Build Coastguard Worker 	}
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker 	return cpid;
31*49cdfc7eSAndroid Build Coastguard Worker }
32