环境:debian8.11.1 64位
方法1:
应用程序:自己编写的C程序
在/etc/init.d目录下增加启动脚本。此处以servmon文件为例,文件内容如下:
#!/bin/sh
### BEGIN INIT INFO
# Provides: servermon
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the GaoxinGateway applications
# Description: starts GaoxinGateway using start-stop-daemon
### END INIT INFO
APPDIR="/home" #此处为应用锁在目录
NAME="Daemon" #此处为要启动的应用的完整路径
#需要启动多个应用可在此函数中增加
do_start()
{
pid=`ps -ef | grep $NAME | grep -v grep | awk '{print $1}'`
if [ z"$pid" = z ]
then
$APPDIR/$NAME >/dev/null 2>&1 &
fi
}
#如果启动多个应用,则有多个关闭命令
do_stop ()
{
pid=`ps -ef | grep $NAME | grep -v grep | awk '{print $1}'`
if [ z&