
1、在需要运行程序的位置创建一个 process.sh 文件
使用 vim ./process.sh 命令点开编辑
将下面脚本复制到文件中保存
#!/bin/bash
#这里可替换为你自己的执行程序,其他代码无需更改
APP_NAME=./backend-1.8.0.jar
#使用说明,用来提示输入参数。如:./process.sh restart
usage() {
echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"
exit 1
}
#检查程序是否在运行
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
#如果不存在返回1,存在返回0
if [ -z "${pid}" ]then
return 1
else
return 0
fi
}
#启动方法
start(){
is_exist
if [ $? -eq "0" ]then
echo "${APP_NAME} is already running. pid=${pid} ."
else
#不输出日志
#nohup java -jar $APP_NAME >/dev/null 2>&1 &
#输出日志
nohup java -jar $APP_NAME >processes.log 2>&1 &
fi
}
#停止方法
stop(){
is_exist
if [ $? -eq "0" ]then
kill -9 $pid
else
echo "${APP_NAME} is not running"
fi
}
#输出运行状态
status(){
is_exist
if [ $? -eq "0" ]then
echo "${APP_NAME} is running. Pid is ${pid}"
else
echo "${APP_NAME} is NOT running."
fi
}
#重启
restart(){
stop
start
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"start")
start
"stop")
stop
"status")
status
"restart")
restart
*)
usage
esac
登录后复制
2、使用 chmod 777 process.sh 为文件授权
3、
./process.sh start 开启程序
./process.sh restart重启程序
./process.sh stop 关闭程序
./process.sh status 查看状态
~#vi tmp.c\x0d\x0a按i进入插入模式,输入源文件内容\x0d\x0a#include \x0d\x0aint main(int argc,char *argv[])\x0d\x0a{\x0d\x0a printf("just a case!\r\n")\x0d\x0a return(0)\x0d\x0a}\x0d\x0a按ESC退出插入模式,输入\x0d\x0a:wq\x0d\x0a回到shell\x0d\x0a~#gcc tmp.c\x0d\x0a~#./a.out在linux下通常使用gedit或vim直接编写.c程序,然后通过gcc指令编译。以Ubuntu系统为例,详细过程如下:
1、进入桌面Temp文件夹
2、右键新建空白文件
3、将文件命名为hello.c
4、进入hello.c,开始编写代码(默认gedit为编辑器)
5、编写代码,保存退出
6、点击右列“终端”,或者直接Ctrl+Alt+T通过快捷组合键进入终端
7、进入hello.c所在目录,通过gcc进行编译、链接、生成可执行文件hello,命令为gcc -o hello hello.c。
8、执行(可执行)文件hello,命令为./hello。
参考资料:
GCC——百度百科
Linux常用命令——百度百科
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)