有些时候我们需要知道某个进程的启动时间!
比如运行:./show.sh mysql 显示mysql进程的启动时间:
显示某PID的启动时间命令:
1 ps -p PID -o lstart
举例子
如下面显示httpd的启动时间:
- for pid in $(pgrep httpd); do echo -n "${pid}"; ps -p ${pid} -o lstart | grep -v "START"; done
比如运行:./show.sh mysql 显示mysql进程的启动时间:
- #!/bin/bash
- if [ -z $1 ]; then
- echo "please input ps keyword" && exit 1
- fi
- ps aux |grep $1 |grep -v "grep $1" |grep -v " $1" |while read line
- do
- linewords=($line)
- pid="${linewords[1]}"
- START_TIME=$(ps -p ${pid} -o lstart | grep -v "START")
- echo "$line $START_TIME"
- done