在用户登录后,我试图在系统启动时自动运行一堆进程。这是我将用来启动一些进程的 create_processes.py 脚本:
#!/usr/bin/python
import subprocess
def f1():
while True:
time.sleep(2)
print "I'm alive"
if len(sys.argv) < 2:
print "assuming main"
subprocess.Popen([""/usr/bin/python",sys.argv[0],"f1"])
elif sys.argv[1] =="f1":
f1()
如果我直接调用它或者如果我尝试nohup python create_processes.py 2>&1 &
一切正常。
当我尝试让它运行由 /etc/profile.d/ 文件夹中的脚本调用时,问题就出现了。此类脚本仅包含上述命令。使用ps
我找不到孩子了。在这种情况下会发生什么?
感谢您的时间,并为我糟糕的英语感到抱歉。
中的文件/etc.profile.d/
是在/etc/profile
执行时获取的。
以下是来自的相关行/etc/profile
:
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
从这一行我们可以看到,只有名称以结尾的文件.sh
才会被获取。
如果您的自定义文件的名称不以 结尾.sh
,请相应地重命名,否则将无法获取。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句