-
Notifications
You must be signed in to change notification settings - Fork 0
/
fg.c
37 lines (37 loc) · 836 Bytes
/
fg.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
#include "headers.h"
void fg(char * input_str)
{
int i,token_cnt=0,id,status;
char * token = strtok(input_str," ");
while(token!=NULL)
{
if(token_cnt==1)
{
id = atoi(token);
}
token = strtok(NULL," ");
token_cnt++;
}
// printf("%d",token_cnt);
if(token_cnt==1||token_cnt>=3)
{
printf("Inconsistent number of arguments\n");
return;
}
else
{
if(id<job_seq_no)
{
kill(jobs[id].pid , SIGCONT);
printf("%s brought to Foreground\n",jobs[id].command);
waitpid(jobs[id].pid, &status, WUNTRACED);
if(WIFSTOPPED(status)==0)
jobs[id].status = 0;
}
else
{
printf("Job not found\n");
return;
}
}
}