顯示某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