-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfg.c
More file actions
52 lines (43 loc) · 1014 Bytes
/
Copy pathfg.c
File metadata and controls
52 lines (43 loc) · 1014 Bytes
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
#include "shell.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <unistd.h>
void exec_fg(int jobid)
{
int pid = -1;
int j = 1;
for (struct child_list *i = root->next; i != NULL; i = i->next, j++)
{
if (j == jobid)
pid = i->pid;
}
if (pid == -1)
{
fprintf(stderr, "no such background process with job number : %d\n", jobid);
return;
}
tcsetpgrp(STDIN_FILENO, pid);
killpg(getpgid(pid), 18);
for (struct child_list *i = root->next; i != NULL; i = i->next)
{
if (i->pid == pid)
{
fg.pid = pid;
strcpy(fg.name, i->name);
fg.status = 1;
delete_node(i);
}
}
int status;
waitpid(pid, &status, WUNTRACED);
if (WIFSTOPPED(status))
{
if(fg.pid != -1)
insert_node(fg.pid, fg.name, 0);
fg.pid = -1;
}
tcsetpgrp(STDIN_FILENO, getpid());
}