其他的部分就不用看了。
The tsh Specification
ctrl-c 需要发送到当前前端job,和所有它的后裔。这个是所谓的前台进程组的概念?
The bg <job> command restarts <job> by sending it a SIGCONT signal, and then runs it in
the background. The <job> argument can be either a PID or a JID.
The fg <job> command restarts <job> by sending it a SIGCONT signal, and then runs it in
the foreground. The <job> argument can be either a PID or a JID.
这个是怎么做到的??
tsh should reap all of its zombie children. If any job terminates because it receives a signal that it didn’t catch, then tsh should recognize this event and print a message with the job’s PID and a description of the offending signal.
这个是什么意思?
Hints
Exceptional Control Flow 不是让你不独异常控制流,兄弟,细心,细心!
The waitpid(), kill(), fork(), execve(), setpgid(), and sigprocmask() functions
will come in very handy. The WUNTRACED and WNOHANG options to waitpid will also be
useful.
kill是用来发送信号的。 setpgid 还没有用 sigprocmask也没有用。 后面两个参数更不知道怎么用哈。
The operating system caps the number of processes any single user can fork. That
said, you will probably want to clean up your environment. The killall and kill commands are
your friends.
kill函数到底是用来干什么的?
When you implement your signal handlers, be sure to send SIGINT and SIGTSTP signals to the en-
tire foreground process group, using “-pid” instead of “pid” in the argument to the kill function.
The sdriver.pl program tests for this error.
为负数就发送到所有的group吗?
One of the tricky parts of the assignment is deciding on the allocation of work between the waitfg
and sigchld handler functions. We recommend the following approach:
– In waitfg, use a busy loop around the sleep function.
– In sigchld handler, use exactly one call to waitpid.
waitfg还不知道在什么使用用。
In eval, the parent must use sigprocmask to block SIGCHLD signals before it forks the child,
and then unblock these signals, again using sigprocmask after it adds the child to the job list by calling addjob. Since children inherit the blocked vectors of their parents, the child must be sure to then unblock SIGCHLD signals before it execs the new program.
竞争条件就是所谓操作通一个list临界区??
The parent needs to block the SIGCHLD signals in this way in order to avoid the race condition where the child is reaped by sigchld handler (and thus removed from the job list) before the parent calls addjob. 在前before?是个什么含义??
When you run your shell from the standard Unix shell, your shell is running in the foreground process group. If your shell then creates a child process, by default that child will also be a member of the foreground process group. Since typing ctrl-c sends a SIGINT to every process in the foreground group, typing ctrl-c will send a SIGINT to your shell, as well as to every process that your shell created, which obviously isn’t correct.
Here is the workaround: 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).