如何不产卵2 proceses我跑的nohup为不同的用户? [英] How do I run nohup as a different user without spawning two proceses?

查看:228
本文介绍了如何不产卵2 proceses我跑的nohup为不同的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想NOHUP命令并运行它以不同的用户,但每次我做这两个进程产生了。

I'm trying to nohup a command and run it as a different user, but every time I do this two processes are spawned.

例如:

$ nohup su -s /bin/bash nobody -c "my_command" > outfile.txt &

这绝对my_command以nobody运行,但有一个额外的过程,我不来体现出来想要的:

This definitely runs my_command as nobody, but there's an extra process that I don't want to shown up:

$ ps -Af
.
.
.
root ... su -s /bin/bash nobody my_command
nobody ... my_command

如果我杀了根的过程中,没有人过程仍然生活...但有没有办法不运行在所有的根进程?由于越来越my_command的ID和杀死它是一个比较复杂一点。

And if I kill the root process, the nobody process still lives... but is there a way to not run the root process at all? Since getting the id of my_command and killing it is a bit more complicated.

推荐答案

这可以实现为:

su nobody -c "nohup my_command >/dev/null 2>&1 &"

和写my_command'的pid在PIDFILE:

and to write the pid of 'my_command' in a pidFile:

pidFile=/var/run/myAppName.pid
touch $pidFile
chown nobody:nobody $pidFile
su nobody -c "nohup my_command >/dev/null 2>&1 & echo \$! > '$pidFile'"

这篇关于如何不产卵2 proceses我跑的nohup为不同的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆