linux切换sid,linux – 将sid字段添加到ps -f输出
我正在閱讀ps手冊(cè)頁(yè),有一些我不明白的東西.
-f does full-format listing. This option can be combined with many other
UNIX-style options to add additional columns. It also causes the
command arguments to be printed. When used with -L, the NLWP (number of
threads) and LWP (thread ID) columns will be added. See the c option,
the format keyword args, and the format keyword comm.
我只想將sid添加到ps -f的輸出中
但我對(duì)以下輸出感到困惑,我的理解是-o應(yīng)該只添加sid到-f的輸出但看起來(lái)像-o覆蓋-f完全.
我知道我可以指定我想要的所有選項(xiàng),如pid,ppid,pgid,sid,user,comm等等,但是有沒(méi)有辦法在-f的輸出中添加一個(gè)額外的列?這就是手冊(cè)頁(yè)所說(shuō)的,對(duì)嗎?
[njia@cst-cgxfile01 ~]$ps -f
UID PID PPID C STIME TTY TIME CMD
njia 3397 26106 0 12:23 pts/1 00:00:00 ps -f
njia 26106 26105 0 09:45 pts/1 00:00:00 -bash
[njia@ ~]$ps -f -o sid
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
SID
26106
26106
25875
25875
25875
25875
25875
[njia@ ~]$
另外,ps -ef -o sid會(huì)將進(jìn)程選擇限制為擁有我的人,這也是一個(gè)驚喜.
解決方法:
要回答問(wèn)題的第一部分,可以添加幾個(gè)標(biāo)志到-f.它們包括-l,-j,-m和-L.不幸的是-o< format>不能與-f結(jié)合使用.
實(shí)際上,獲得您想要的最佳方法是準(zhǔn)確指定您想要的內(nèi)容,例如:
ps -e -o pid,ppid,pgid,sid,user,comm
但是你可以通過(guò)將-j添加到-f來(lái)實(shí)現(xiàn)ps -efj.這會(huì)添加PGID和SID列.
在沒(méi)有-e標(biāo)志的情況下演示以縮短輸出,比較:
$ps -f
UID PID PPID C STIME TTY TIME CMD
myuser 123 4513 0 18:20 pts/26 00:00:00 zsh
myuser 1282 123 0 18:20 pts/26 00:00:00 ps -f
$ps -fj
UID PID PPID PGID SID C STIME TTY TIME CMD
myuser 123 4513 123 123 0 18:20 pts/26 00:00:00 zsh
myuser 1402 123 1402 123 0 18:20 pts/26 00:00:00 ps -fj
為了回答你問(wèn)題的第二部分,ps -ef -o sid只顯示你自己的進(jìn)程的原因是它在決定你的標(biāo)志不符合POSIX時(shí)切換到BSD模式.這由消息指示
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
所以它相當(dāng)于運(yùn)行ps ef o sid.
在BSD模式中,e表示它將打印進(jìn)程的環(huán)境,f表示“森林”.并且BSD模式默認(rèn)打印當(dāng)前用戶擁有的具有任何終端的所有進(jìn)程,而不僅僅是當(dāng)前終端上的進(jìn)程.
嘗試將-o sid更改為-o sid,cmd以查看e和f選項(xiàng)的效果.
$ps ef o sid
SID
12345
567
567
...
$ps ef o sid,cmd
SID CMD
12345 -zsh USER=... LOGNAME=...
567 zsh PWD=... LANG=...
567 \_ ps ef o sid,cmd LANG=... PWD=...
...
并且與ps u比較,看到顯示的過(guò)程是相同的(為了簡(jiǎn)潔,我添加了| wc -l).
$ps ef o cmd | wc -l
20
$ps u | wc -l
20
標(biāo)簽:linux,ps
來(lái)源: https://codeday.me/bug/20190816/1667408.html
總結(jié)
以上是生活随笔為你收集整理的linux切换sid,linux – 将sid字段添加到ps -f输出的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 原版Win7注入USB3.0驱动和NVM
- 下一篇: linux c++ 编译 库,LINUX