运行tail|grep后按下Ctrl-C的过程中发生了什么
source link: https://www.lujun9972.win/blog/2018/08/16/%E8%BF%90%E8%A1%8Ctail%7Cgrep%E5%90%8E%E6%8C%89%E4%B8%8Bctrl-c%E7%9A%84%E8%BF%87%E7%A8%8B%E4%B8%AD%E5%8F%91%E7%94%9F%E4%BA%86%E4%BB%80%E4%B9%88/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
运行tail|grep后按下Ctrl-C的过程中发生了什么
从 https://ubuntuforums.org/showthread.php?t=1761120&s=bbaf101ffbcc9abdb032d90cff01fc36 中看到的,记录一下
在shell中运行 tail|grep 时发生了什么
运行tail
- shell调用fork产生子进程
- 重置信号处理函数为SIG_DFL
- 产生新的进程组,并将子进程设置为该进程组的leader
- exec tail
运行grep
- shell调用fork产生子进程
- 重置信号处理函数为SIG_DFL
- 将进程加入到
tail
产生的进程组中 - exec tail
将新产生的进程组放到前台,控制终端
- tcsetpgrp(STDIN_FILENO, tail进程组);
当按下Ctrl-c时发生了什么
根据 setpgrp
manual page 的说法,按下 Ctrl-c
后:
- 终端产生
SIGINT
信号 - 前台进程组中的所有进程都会接收到
SIGINT
信号然后退出(默认动作) - shell通过调用
waitpid
清理进程表中子进程信息
Related Issues not found
Please contact @lujun9972 to initialize the comment
Generated by Emacs 27.x(Org mode 9.x)
Copyright © 2014 - 2021 lujun9972
-
Powered by EGO
Themed with emacs_love
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK