Add the programs ␀ and pack
[minish.git] / Devember / log03.txt
blob6474a20d10b72c78cd3ca9e8e9ca49a78e22d432
1 When minish is called without arguments, it reads from stdin.
2 This is interactive mode.
3 When it is called with an argument, it reads from the file thus named.
4 This is script mode.
6 In interactive mode,
7 minish should not terminate when Ctrl+C is pressed
8 and a command is executing.
9 There are two ways of doing this:
10 ignoring SIGINT,
11 or avoid being in the foreground process group so to not receive it.
12 Yesterday minish used the first way, but today I use the second.
14 When minish spawns a new process, with fork(),
15 this process puts itself in a new group just for itself
16 and declares this group as foreground.
17 When the child process terminates,
18 minish declare its own process group as foreground.
20 tcsetpgrp(fd, gpid) puts the gpid process group in the foreground
21 of the fd terminal.
22 If gpid is in the background, it receives the signal SIGTTOU;
23 it means “stay put: you can do any output right now”
24 and its default action is to suspend, but it can be ignored.
25 So, the child must:
26 1. create its own process group;
27 2. disable the handling of SIGTTOU;
28 3. puts its process group in the foreground;
29 4. re-enable the handling of SIGTTOU.
31 Using process groups paves the way to job control.
32 Without process groups, the shell could ignore SIGINT anyway,
33 but other background processes cannot:
34 if they did, we would be unable to stop them.
36 Enough for today.
38 Suggested readings:
39 https://vidarholen.net/contents/blog/?p=34
40 https://gnu.org/software/bash/manual/html_node/Job-Control-Basics.html