linux下如何让控制台程序后台运行

时间:2014-05-07 15:03:04   收藏:0   阅读:421

方法1:./test & 
方法2:(./test &) 
方法3:nohup 和bg 

方法4:screen -mS test /root/test   退出程序需要手动进入screen创建的test虚拟终端去退出

方法5:修改并保存一下代码为脚本,运行
#!/bin/bash

NAME=$(basename "$0")
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/root #程序路径
DESC=alserver#程序描述
USER=root#运行程序的用户

test -x "$DAEMON" || exit 0

case "$1" in
start)
echo -n "Starting $DESC: "
su "$USER" -c "$(printf "%q -q &" "$DAEMON" )"
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
killall --quiet "$DAEMON"
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
killall --quiet "$DAEMON"
sleep 1
su "$USER" -c "$(printf "%q -q &" "$DAEMON" )"
;;
*)
printf "Usage: %q {start|stop|restart|force-reload}\n" "$0" >&2
exit 1
;;
esac

exit 0

linux下如何让控制台程序后台运行,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!