有谁知道一种监视根进程生成的简单方法

cer*_*ier 14 linux unix monitoring process

我想在新的根进程产生时执行一个脚本。(在 Linux 上)我怎么能简单地做到这一点?

谢谢

Sco*_*ack 9

对于auditd来说,这听起来是个完美的工作。一旦您运行了 auditd(现代基于 RedHat 的系统上的默认服务),您就可以制定一个规则,通过执行

auditctl -a task,always -F uid=0

打破这个命令规则,过度使用手册页,我们发现:

   -a list,action
          task       Add  a  rule to the per task list. This rule list is used
                     only at the time a task is created -- when fork() or
                     clone() are called by the parent task. When using this
                     list, you should only use fields that are known at task
                     creation time, such as the uid, gid, etc.
          always     Allocate an audit context, always fill it in at syscall 
                     entry time, and always write out a record at syscall exit
                     time.
Run Code Online (Sandbox Code Playgroud)

因此,每当 fork 或 clone 系统调用退出时,请始终为此操作写出记录。

最后一个选项可以被认为是一个过滤字符串,在我们的使用中-F uid=0只是将我们限制在进程所有者的 uid 为 0 的情况下。

请注意,此规则可以在运行时执行,方法是确保正确配置了 auditd,并将​​规则添加
-a task,always -F uid=0
到分发的相关文件中,很可能/etc/audit/audit.rules

请记住,这会非常嘈杂,无论是谁在进行日志审查都需要为此做好准备。