@@ -51,6 +51,8 @@ char *detpath(char *);
51
51
char * * args_proc (char * , struct tokens * );
52
52
53
53
int redirection (char * , int );
54
+ void parent_sig_handler ();
55
+ void child_sig_handler ();
54
56
55
57
const int MAX_PATH_SIZE = 128 ;
56
58
@@ -127,11 +129,16 @@ int shell_exec(struct tokens *tokens){
127
129
cpid = fork ();
128
130
/* cpid > 0 - parent process, cpid == 0 - child process, cpid < 0 - error */
129
131
if (cpid > 0 ) {
132
+ parent_sig_handler ();
133
+
134
+ pid_t pid = getpid ();
135
+ setpgid (pid , 0 );
136
+ pid_t pgid = getpgid (0 );
137
+ tcsetpgrp (0 , pgid );
138
+
130
139
wait (& status );
131
140
} else if (cpid == 0 ){
132
- /* set process group id */
133
- // setpgid(getpid(), 0);
134
- //tcsetpgrp(0, getpgid(getpid()));
141
+ child_sig_handler ();
135
142
/* executes program according to path and given arguments */
136
143
execv (path , args );
137
144
exit (0 );
@@ -150,6 +157,18 @@ int shell_exec(struct tokens *tokens){
150
157
return 1 ;
151
158
}
152
159
160
+ void parent_sig_handler (){
161
+ signal (SIGINT , SIG_IGN );
162
+ signal (SIGTSTP , SIG_IGN );
163
+ signal (SIGQUIT , SIG_IGN );
164
+ }
165
+
166
+ void child_sig_handler (){
167
+ signal (SIGINT , SIG_DFL );
168
+ signal (SIGTSTP , SIG_DFL );
169
+ signal (SIGQUIT , SIG_DFL );
170
+ }
171
+
153
172
/* processes arguments to determine what is this redirection or merely arguments passing */
154
173
char * * args_proc (char * path , struct tokens * tokens ){
155
174
int i ;
0 commit comments