问题描述
我有一个运行在Redhat Linux受限版本上的NAS.我按照说明进行操作,以便可以进行shell访问,这对我有很大帮助.我还做了一些修改,其他人做了一些修改,除了一个问题,它们似乎都可以正常工作.
I have an NAS running on a limited version of what appears to be Redhat Linux. I followed directions to hack it so I could have shell access, which has been a big help. I've also made a couple modifications, ones that others have done and, other than one issue, they all seem to work fine.
每隔22天,系统就会关闭一次.我使用运行ps的脚本来发现实际上已调用了shutdown,但是我不知道什么程序会调用shutdown.
Somehow, every 22 days, the system shuts down. I used a script running ps to find that shutdown is actually called, but I don't know what program calls shutdown.
如果我重命名/sbin/shutdown,则可以编写脚本来替换它.但是我想要的最重要的信息是什么程序正在调用shutdown.
If I rename /sbin/shutdown, then I could write a script to replace it. But the most important piece of information I'd like is what program is calling shutdown.
如果一个程序运行了我的脚本(伪造的/sbin/shutdown),我如何找出哪个程序调用了我的脚本?我希望能够从脚本中首先确定哪个程序称为脚本.如果这样更容易,我总是可以使用Perl脚本而不是bash脚本.
If a program runs my script (the phony /sbin/shutdown), how can I find out what program called my script? I want to be able to, from within the script, determine what program called the script in the first place. If it makes it easier, I can always use a Perl script instead of a bash script.
推荐答案
在Bash中, ps -p $$ -o ppid =
.输出是父进程(调用进程)的pid.有了父pid,您可以从/proc/< pid>/cmdline
(有关procfs的更多信息).
In Bash, ps -p $$ -o ppid=
. The output is the pid of the parent process (the calling process). Having the parent pid, you can read its command line from /proc/<pid>/cmdline
(more on procfs).
这篇关于查找哪个程序运行另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!