-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (55 loc) · 1.4 KB
/
main.cpp
File metadata and controls
74 lines (55 loc) · 1.4 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "src/base.hpp"
#include <sys/types.h>
#include <string>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
using namespace std;
void execute(base* b);
base* parsing(string input);
int main (int argv, char* argc[]){
/* pid_t children = fork();
int status;
char* arg[2];
std::string command_1("ps");
arg[0] = (char*)command_1.c_str();
arg[1] = NULL;
if(children > 0){
printf("We are in the Parent.\n");
printf(" Parent_ID: %d\n", getpid());
printf(" Child_ID: %d\n\n", children);
if(waitpid(children, &status , WNOHANG|WUNTRACED ) == 0){
wait(NULL);
if (WIFEXITED(status))
printf("Child ended normally!\n");
else if (WIFSIGNALED(status))
printf("Child ended because of an uncaught signal!\n");
else if (WIFSTOPPED(status))
printf("Child process has stoped!\n");
exit(EXIT_SUCCESS);
}
if(waitpid(children, &status , WNOHANG|WUNTRACED ) < 0)
exit(EXIT_FAILURE);
}
if(children == 0){
printf("We are in the Child.\n");
printf(" Child_ID: %d\n",getpid());
printf(" Parent_ID: %d\n", getppid());
printf("Calling execvp() with command <ps>\n");
execvp(arg[0], arg);
}
if(children < 0){
perror("fork() error");
exit(-1);
}
*/
return 0;
}
base* parsing(string input) {
base* b;
return b;
}
void execute(base* b) {
b->compute();
}