-
Notifications
You must be signed in to change notification settings - Fork 0
/
fore_process.c
33 lines (26 loc) · 878 Bytes
/
fore_process.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
#include "headers.h"
void run_in_foreground(char** argument_list){
pid_t fore_pid = fork();
// starting timer
time_t process_begin_clock = time(NULL);
if (fore_pid < 0){
perror("Could not create forked process");
process_exec_time = 0;
return;
} else if (fore_pid == 0){
if ( execvp(argument_list[0], argument_list) < 0){
printf("Command not found\n");
}
exit(EXIT_SUCCESS);
} else {
is_foreground_running = 1;
cur_foreground_process_pid = fore_pid;
// strcpy(cur_foreground_process_name, argument_list[0]);
int process_status;
waitpid(fore_pid, &process_status, WUNTRACED);
is_foreground_running = 0;
}
// Ending process
time_t process_end_clock = time(NULL);
process_exec_time = process_end_clock - process_begin_clock;
}