-
Notifications
You must be signed in to change notification settings - Fork 1
/
fg.c
54 lines (48 loc) · 1.19 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
/*
Nome: Rodrigo Fernandes da Costa
n. USP: 6793073
Nome: Lucas de Moraes Franco
n. USP: 6793239
*/
#include "main.h"
void fg(struct command headCommand){
struct argument * argument;
struct command * command;
int id;
if(headCommand.argNumber != 2 || (!sscanf(headCommand.argument.next->string,"%d",&id))){
printf("error> expected \"fg process number\", but found: ");
argument = & ( headCommand . argument ) ;
while ( argument ) {
printf("%s ",argument->string);
argument = argument -> next ;
}
printf("\n");
return;
}
command = & headCommand;
while(command = command -> next){
if(command->id == id){
if(command->status == running){
command->status = foreground;
waitpid(command->id,NULL,WUNTRACED);
if(command -> status != suspended){
command -> status = finish;
}
fflush(stdin);
return;
}
if(command->status == suspended){
command->status = foreground;
kill(command->id, SIGCONT);
waitpid(command->id,NULL,0);
if(command -> status != suspended){
command -> status = finish;
}
fflush(stdin);
return;
}
printf("error> %d is not suspended or running\n", id);
}
}
printf("error> %d not found\n", id);
}