Shell lab
# Shell lab
提示
/* Here are the functions that you will implement */
void eval(char *cmdline);
int builtin_cmd(char **argv);
void do_bgfg(char **argv);
void waitfg(pid_t pid);
void sigchld_handler(int sig);
void sigtstp_handler(int sig);
void sigint_handler(int sig);
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
execve
不会继承之前设置的signal handler
- A child created via fork(2) inherits a copy of its parent's signal mask; the signal mask is preserved across execve(2).
man 2 sigprocmask
- When you implement your signal handlers, be sure to send SIGINT and SIGTSTP signals to the entire foreground process group, using ”-pid” instead of ”pid” in the argument to the kill function.The sdriver.pl program tests for this error.
- After the fork, but before the execve, the child process should call setpgid(0, 0), which puts the child in a new process group whose group ID is identical to the child’s PID. This ensures that there will be only one process, your shell, in the foreground process group. When you type ctrl-c, the shell should catch the resulting SIGINT and then forward it to the appropriate foreground job (or more precisely, the process group that contains the foreground job).
编辑 (opens new window)