-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsig.c
44 lines (42 loc) · 889 Bytes
/
sig.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
#include "headers.h"
int sig(char *cmd)
{
cmd[strcspn(cmd, "\n")] = 0;
char *token1;
char *strtokUser;
strtok_r(cmd, " ", &strtokUser);
int jobNum, sigNum;
char *jobNu = strtok_r(NULL, " ", &strtokUser);
if (jobNu == NULL)
{
perror("Job Number is NULL");
return 0;
}
jobNum = atoi(jobNu);
char *signu = strtok_r(NULL, " ", &strtokUser);
if (signu == NULL)
{
perror("Sig Number is NULL");
return 0;
}
sigNum = atoi(signu);
int i = 0;
for (i = 0; i < totalbgJobs; i++)
{
if (jobsArr[i].jobid == jobNum)
{
break;
}
}
if (i == totalbgJobs)
{
printf("Job Number does not exist\n");
return 0;
}
if (kill(jobsArr[i].pid, sigNum) < 0)
{
printf("Could not execute\n");
return 0;
}
return 0;
}