-
Notifications
You must be signed in to change notification settings - Fork 0
/
fg.c
64 lines (47 loc) · 1.38 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "headers.h"
int flag1=0,flag2=0;
void handle1(int sig)
{ flag1=1;}
void handle2(int sig)
{flag2=1;}
void fg(char **comm,int proc[],char *procname[1000],int *sze)
{ global=1;
if(comm[1]==NULL)
{global=-1;printf("error : give the job number too\n");return;}
if(comm[2]!=NULL){global=-1;printf("TOO MANY ARGUMENTS\n");return;}
int i,j,k;
for(i=0;comm[1][i]!='\0';i++)
{ if(comm[1][i]<48||comm[1][i]>57)
{global=-1;printf("INVALID job number\n");return;}
}
int x=atoi(comm[1]);
j=0;
for(i=0;i<1000;i++)
{if(proc[i]<=0)
{continue;}
j++;
int g=0;
if(j==x)
{ int a;
kill(proc[i],SIGCONT);
signal(SIGINT,handle1);
tcsetpgrp(STDIN_FILENO,proc[i]);
signal(SIGTTIN,SIG_IGN);
signal(SIGTTOU,SIG_IGN);
waitpid(proc[i],&a,WUNTRACED);
tcsetpgrp(STDIN_FILENO,getpgrp());
signal(SIGTTIN,SIG_DFL);
signal(SIGTTOU,SIG_DFL);
if(a>0)
{global=-1;}
if(WIFSTOPPED(a))
{ break;
}
else if(flag1==1)
{proc[i]=-1;}
break;
}
}
if(j!=x)
{global=-1;printf("NO SUCH JOB nUMBER\n");}
}