小编And*_*nko的帖子

bash ps打印有关名称的进程的信息

我需要使用ps类型名称的进程来打印UID PID PPID PRI NI VSZ RSS STAT TTY TIME列。

  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
Run Code Online (Sandbox Code Playgroud)

但是,当我将此命令与参数$ 2 = bash一起使用时,它什么也不会打印(此过程存在)

更新

  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
Run Code Online (Sandbox Code Playgroud)

这对我有用,但是实际上,恕我直言,此解决方案不是最佳解决方案。我在grep名称之后使用阴影列命令,并打印除命令外的所有列。

unix bash grep ps nano

4
推荐指数
1
解决办法
2289
查看次数

标签 统计

bash ×1

grep ×1

nano ×1

ps ×1

unix ×1