-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.c
More file actions
42 lines (35 loc) · 908 Bytes
/
init.c
File metadata and controls
42 lines (35 loc) · 908 Bytes
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
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
pid_t shell_pgid;
struct termios shell_tmodes;
int shell_terminal;
int shell_is_interactive;
void init_shell(){
shell_terminal = STDIN_FILENO;
shell_is_interactive = isatty(shell_terminal);
if(shell_is_interactive){
while(tcgetpgrp(shell_terminal) != (shell_pgid=getpgrp())){
kill(- shell_pgid, SIGTTIN);
}
signal (SIGINT, SIG_IGN);
signal (SIGQUIT, SIG_IGN);
signal (SIGTSTP, SIG_IGN);
signal (SIGTTIN, SIG_IGN);
signal (SIGTTOU, SIG_IGN);
signal (SIGCHLD, SIG_IGN);
shell_pgid=getpid();
if(setpgid(shell_pgid,shell_pgid)<0){
perror("Failed");
exit(1);
}
tcsetpgrp(shell_terminal,shell_pgid);
tcgetattr(shell_terminal,&shell_tmodes);
}
}