Linux平台下停止后台进程脚本编写
来源:互联网 发布:bluehost域名跳转 编辑:程序博客网 时间:2024/06/05 19:14
1、场景说明
- [root@master ~]# jps -m
- 33050 Jps -m
- 3299 NameNode
- 3747 ResourceManager
- 9028 ConsoleConsumer --zookeeper 192.168.168.200:2181 --topic BusTicket
- 4331 Worker --webui-port 8081 spark://master:7077
- 3400 DataNode
- 3849 NodeManager
- 4450 Kafka config/server.properties
- 9303 ConsoleConsumer --zookeeper 192.168.168.200:2181 --topic Result
- 4243 Master --host master --port 7077 --webui-port 8080
- 3590 SecondaryNameNode
- 4413 QuorumPeerMain /usr/local/zookeeper/zookeeper-3.4.5/bin/../conf/zoo.cfg
使用jps -m 命令查看当前运行的java进程,如果我现在需要删除【9028 ConsoleConsumer --zookeeper 192.168.168.200:2181 --topic BusTicket】这个进程:
获取进程执行pid,以便使用kill指令关闭进程
这里使用的 | 管道连接指令的方法。
1、 显示所有进程详情
2、 不显示 grep自身进程
3、 查找进程对应的关键字 ‘BusTicket’,注意必须是此进程独有的关键字
4、 使用awk指令获取 pid 数值
- [root@master ~]# ps -ef | grep -v grep | grep BusTicket | awk '{print $2 }'
- 9027
之后再使用kill -9 9027 ,为了方便快捷,采用shell脚本停止后台进程更加好。
2、创建脚本文件 stopServer.sh
- #!/bin/sh
- ### find pid
- pid=`ps -ef | grep -v grep | grep BusTicket | awk '{print $2 }'`
- if [ -n "$pid" ];then
- ### kill pid
- kill -9 $pid
- ### check status
- process_count=`ps -ef | grep -v grep | grep BusTicket | wc -l`
- while [ $process_count -ne 0 ]
- do
- sleep 2
- process_count=`ps -ef | grep -v grep | grep BusTicket | wc -l`
- done
- echo 'BusTicket is stoped'
- else
- echo 'can not find BusTicket'
- fi
阅读全文
0 0
- Linux平台下停止后台进程脚本编写
- Linux 下Java 进程启动停止shell脚本
- Linux下后台守护进程的编写实例
- Linux下后台守护进程的编写实例
- 停止linux后台进程的方法
- linux 下停止,继续进程
- 基于linux平台下domino启动脚本编写
- Linux平台下启动java程序的脚本编写
- Linux下后台执行脚本
- Linux下后台守护进程
- Linux ssh exit,启动的后台进程不会停止
- Linux ssh exit,启动的后台进程不会停止
- Linux 下停止tomcat 进程没有停止,需要手动kill
- UNIX/LINUX平台的进程后台运行
- linux下编写shell脚本
- linux下编写shell脚本
- Linux下编写守护进程
- Linux下编写守护进程
- PAT A1057. Stack (30)
- ios 设置webview透明背景
- IOCP完成端口的一个简单封装类
- 转 Windows+VS2013爆详细Caffe编译安装教程
- 将Linux的私钥文件.id转换为Putty的ppk文件
- Linux平台下停止后台进程脚本编写
- 数据结构与算法——希尔排序
- (JS)LeetCode之路001-Two Sum
- 定义一个2维数组3行4列,求数组平均值最大值最小值js
- IDEA+Gradle+SpringBoot+SpringDataJPA+lambok(lombok有点问题)(一)
- 性能测试
- Linux系统调用原理
- 用props在外部子组件中使用父组件的数据
- LeetCode算法题——Longest Substring Without Repeating Characters