-
Notifications
You must be signed in to change notification settings - Fork 13
/
jd_work.c
59 lines (45 loc) · 935 Bytes
/
jd_work.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: MIT
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <errno.h>
#include "jitterdebugger.h"
static pid_t bpid;
int start_workload(const char *cmd)
{
int err;
if (!cmd)
return 0;
bpid = fork();
if (bpid > 0)
return 0;
if (bpid < 0)
return errno;
err = setpgid(0,0);
if (err)
err_handler(errno, "setpgid()");
printf("start background workload: %s\n", cmd);
err = execl("/bin/sh", "sh", "-c", cmd, (char *)0);
if (err) {
err_handler(err, "execl()");
exit(EXIT_FAILURE);
}
exit(0);
}
void stop_workload(void)
{
int status;
int err;
if (bpid == 0)
return;
err = killpg(bpid, SIGTERM);
if (err)
err_handler(errno, "kill()");
if (!waitpid(bpid, &status, 0))
err_handler(errno, "waitpid()");
err = WEXITSTATUS(status);
if (WIFEXITED(status) && err)
warn_handler("workload exited with %d", err);
}