我需要打印UID PID PPID PRI NI VSZ RSS STAT TTY TIME使用ps鍵輸入名稱的進程。bash ps打印有關進程名稱的信息
GNU nano 2.0.6
File: file2
ps o uid,pid,ppid,ni,vsz,rss,stat,tty,time | grep $2 > $1
cat $1
echo "enter pid of process to kill:"
read pid
kill -9 $pid
但不打印輸出,當我用參數$ 2 =的bash命令(此過程中存在)
UPDATE
GNU nano 2.0.6
File: file2
ps o uid,pid,ppid,ni,vsz,rss,stat,tty,time,command | grep $2 | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9}' > $1
cat $1
echo "enter pid of process to kill:"
read pid
kill -9 $pid
這對我的作品,但實際上這種解決方案恕我直言,不是最好的。我使用陰影列命令,在什麼grep名字後打印所有不包括命令的列。
你已經錯過了'comm'列('comm' - 只是命令的名字 - 最好的'grep的bash','cmd' - 命令參數,'grep的bash'會失敗) –
而不是長'awk'命令,您可以使用'cut -d','-f-9'。更好的是,爲了避免'awk' /'cut',你可以使用'ps o uid,pid,(...),tty,time $(pgrep $ 2)' – silel