-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforegroundprocess.h
More file actions
54 lines (53 loc) · 1.24 KB
/
Copy pathforegroundprocess.h
File metadata and controls
54 lines (53 loc) · 1.24 KB
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
#ifndef FG_PROC
#define FG_PROC
#include "global.h"
int fork_fun_proc(int flag)
{
curFgProc = flag;
int status, ret;
pid_t pflag = getpgid(flag);
signal(22, SIG_IGN); // write to ctrl terminal
signal(21, SIG_IGN); // read to ctrl terminal
tcsetpgrp(0, pflag);
if (waitpid(flag, &status, WUNTRACED) == -1)
{
return 0;
}
end_Sec = time(NULL);
pid_t shellflag = getpgid(Shell_Id);
tcsetpgrp(0, shellflag);
// default
signal(22, SIG_DFL); // write ctrl back to terminal
signal(21, SIG_DFL); // read ctrl back to terminal
return 1;
}
int fgProc()
{
start_sec = time(NULL);
pid_t flag = fork();
if (flag < 0) // no process
{
printf("%s: could not fork child\n", commands[0]);
return 0;
}
if (flag) // process. yes.
{
int fgproc_check = fork_fun_proc(flag);
curFgProc = Shell_Id;
return (fgproc_check);
}
else // child process
{
commands[numargs] = NULL;
int checkchild = execvp(commands[0], commands);
if (checkchild < 0)
{
printf("%s: No such command exists \n", commands[0]);
raise(17);
_exit(1);
}
exit(0);
}
return 1;
}
#endif