-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkjob.c
More file actions
61 lines (55 loc) · 1.06 KB
/
Copy pathkjob.c
File metadata and controls
61 lines (55 loc) · 1.06 KB
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
60
61
#include "header.h"
ll KJOB(char **com)
{
ll len=0;
while(com[len]!=NULL)
len++;
if (len != 3)
{
perror("kjob: Incorrect no. of argument");
return 1;
}
ll i=0;
while (com[1][i]!='\0')
{
if (com[1][i]<'0' || com[1][i]>'9')
{
perror("kjob: Incorrect jobnumber");
return 1;
}
i++;
}
i=0;
while (com[2][i]!='\0')
{
if (com[2][i]<'0' && com[2][i]>'9')
{
perror("kjob: Incorrect signal no.");
return 1;
}
i++;
}
ll jobnum = atoi(com[1]), signum = atoi(com[2]);
ll c=1;
for (i = 0; i < 1024; i++)
{
if (bg_jobs[i]==-1)
continue;
if (c==jobnum)
{
if (kill(bg_jobs[i],signum)==-1)
{
perror("kill() error");
return 1;
}
break;
}
c++;
}
if (c!=jobnum)
{
printf("Invalid job number\n");
return 1;
}
return 0;
}