-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
80 lines (56 loc) · 1.07 KB
/
Copy pathmain.c
File metadata and controls
80 lines (56 loc) · 1.07 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
75
#include "header.h"
void SIGINT_handler();
void SIGCHLD_handler();
void SIGINT_handler()
{
signal(SIGINT, SIG_IGN);
printf("Handled\n");
}
void SIGCHLD_handler()
{
printf("Process exited!\n");
}
int main()
{
joblist[0].pid=-1;
shellpid=getpid();
arr=(char**)malloc(40000*sizeof(char*));
int i;
for(i=0 ; i<40000; i++)
{
arr[i]=(char*)malloc(20*sizeof(char));
}
home=(char *)malloc(100*sizeof(char));
getcwd(home, 100);
/*SIGNAL HANDLERS*/
struct sigaction sVal;
sVal.sa_flags = SA_RESTART;
sVal.sa_sigaction = &HandleSignal;
sigfillset(&sVal.sa_mask);
if(sigaction(SIGINT, &sVal, NULL)<0)
perror("Error");
if(sigaction(SIGCHLD, &sVal, NULL)<0)
perror("Error");
// printf("Helo");
signal(SIGINT, ctrlC);
signal(SIGTSTP, ctrlZ);
// signal(SIGCHLD, SIGCHLD_handler);
char **tokens;
do
{
display(home);
tokens=get_command();
if(tokens == NULL)
{
perror("Error");
continue;
}
int pos=0;
while(tokens[pos]!=NULL)
{
int num=0;
piping(seperate_command(tokens[pos++] , &num) , &num, home);
}
}while(1);
return 0;
}