-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg.c
39 lines (38 loc) · 889 Bytes
/
bg.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
#include "headers.h"
#include "bg.h"
void bg_implementation(int parts, char **args)
{
if (parts > 1)
{
printf("bg: too many arguments \n");
return;
}
if (parts < 1)
{
printf("bg: too few arguments \n");
return;
}
int proc_shell_id = atoi(args[0]);
if (proc_shell_id < 0)
{
printf("bg: invalid proc shell id \n");
return;
}
pid_t pid = get_pid_from_id(proc_shell_id, head);
if (pid == -1)
{
printf("bg: no process running for the given shell id \n");
return;
}
int r1 = kill(pid, SIGCONT); // Changes the state of process to running (in the # background).
if (r1 < 0)
{
printf("bg: error changing state of the process \n");
return;
}
else
{
printf("bg: state of the process changes successfully \n");
}
return;
}