linux shell 中判断进程存在
来源:互联网 发布:金庸群侠传x如何删数据 编辑:程序博客网 时间:2024/04/28 20:11
1. ps
user@user-ThinkPad-Edge:~$ ps -efUID PID PPID C STIME TTY TIME CMDuser 2111 1 0 09:02 ? 00:00:03 evolutionuser 2113 1 0 09:02 ? 00:00:00 /usr/lib/bamf/bamfdaemonuser 2132 1 48 09:02 ? 00:27:19 /usr/lib/firefox-3.6.20/firefox-binps -p 根据给定的pid参数判断是否有这个进程,如果有这个进程正常退出,退出值0.如果没有这个进程异常退出,退出值1
user@user-ThinkPad-Edge:~$ ps -p 2111 PID TTY TIME CMD 2111 ? 00:00:03 evolutionuser@user-ThinkPad-Edge:~$ echo $?0user@user-ThinkPad-Edge:~$ user@user-ThinkPad-Edge:~$ ps -p 3333 PID TTY TIME CMDuser@user-ThinkPad-Edge:~$ echo $?1
2. pgrep
pgrep根据给出的进程名判断是否有这个名字的进程。如果有这个名字的进程正常退出,退出值0.如果没有这个名字的进程异常退出,退出值1.
user@user-ThinkPad-Edge:~$ pgrep evolution18302111user@user-ThinkPad-Edge:~$ echo $?0user@user-ThinkPad-Edge:~$ pgrep hellouser@user-ThinkPad-Edge:~$ echo $?1
3. /proc
每个进程都会在/proc下有一个以进程PID命名的目录。
user@user-ThinkPad-Edge:~$ ls /proc/2111attr clear_refs coredump_filter environ fdinfo limits mem mountstats oom_score root sessionid stat syscallauxv cmdline cpuset exe io loginuid mountinfo net pagemap sched smaps statm taskcgroup comm cwd fd latency maps mounts oom_adj personality schedstat stack status wchan
编写bash脚本判断一个进程是否存在
#!/bin/bashif [ -z $1 ]then echo "Need a pid argument" exit 1fiif [ -d /proc/$1 ];then exit 0else exit 1fi
- linux shell 中判断进程存在
- linux shell 判断进程是否存在
- shell脚本中判断进程是否存在
- linux中shell编程: 使用pgrep指令判断进程是否存在
- linux判断进程或者cron是否存在shell
- linux shell 中判断文件、目录是否存在
- shell:判断一个进程是否存在
- shell脚本循环判断进程是否存在
- shell脚本判断Apache进程是否存在
- Linux shell判断文件是否存在
- linux shell 判断文件是否存在
- linux shell 判断文件是否存在
- Linux shell判断文件是否存在
- Linux Shell 判断环境变量 是否存在
- ubuntu中shell判断文件存在
- shell脚本中判断文件是否存在
- shell 判断postgresql中用户是否存在?
- 【shell】判断文件中是否存在字符串
- 通过命令行执行PHP文件写字符到外部文本 & server端与客户端的当下绝对路径 & PHP的时间设定
- C++ traits编程方法
- Mysql 的 Cascade/Restrict/No action
- CharacterControllerr的碰撞检测
- CentOS构建自己的发行版
- linux shell 中判断进程存在
- 在编译linux kernel时出现 “make: arm-none-linux-gnueabi-gcc:命令未找到”
- EXT核心API详解(六)-Ext.Fx
- 关于从sql*plus中往数据库插入数据却查询不到的原因
- CSS3_HTML5_JS好站
- Qt ProgressBar
- (七)Ext.KeyNav/KeyMap/JSON/Format/DelayedTask/TaskRunner/TextMetrics/XTemplate
- js submit 出错
- EXCEL学习笔记(1)