“Shell获取进程id”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
→‎R
 
第20行: 第20行:
  
 
</pre>
 
</pre>
=R=
+
=references=
 
[https://blog.csdn.net/niu_88/article/details/117443175  shell获取进程ID]
 
[https://blog.csdn.net/niu_88/article/details/117443175  shell获取进程ID]
 
[[category:shell]]
 
[[category:shell]]

2022年7月6日 (三) 07:11的最新版本

Command

shell脚本中查看某进程ID
比如,查看进程niugge的PID

pid=$(ps -ef | grep jenkins | grep -v grep | awk 'NR==1 {print $2}')



grep niugge, 过滤出niugge所在行
grep -v grep, 过滤掉grep所在行
NR==1,代表第一行
print $2, 返回第二列的值,即PID所在列

最后,返回的值保存到pid中,可以使用此值进程操作。

jepid=$(ps -ef | grep jenkins  | grep -v grep  |awk 'NR==1 {print $2}')
kill $jepid


references

shell获取进程ID