国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

linux shell pgrep命令使用方法(pgrep指令)獲取進(jìn)程號(hào)、統(tǒng)計(jì)進(jìn)程數(shù)量(學(xué)會(huì)區(qū)分Linux進(jìn)程進(jìn)程名)

這篇具有很好參考價(jià)值的文章主要介紹了linux shell pgrep命令使用方法(pgrep指令)獲取進(jìn)程號(hào)、統(tǒng)計(jì)進(jìn)程數(shù)量(學(xué)會(huì)區(qū)分Linux進(jìn)程進(jìn)程名)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

問題背景

按照我之前,在腳本中,獲取除腳本自身進(jìn)程之外與腳本同名進(jìn)程號(hào)的方法:

ps -ef | grep "${SCRIPT_NAME}" | grep -v "grep" | awk '{print $2}' | grep -v "$PID"

這種方法有很大問題,莫名奇妙的,它無法正常過濾掉grep的進(jìn)程(這里面還有點(diǎn)復(fù)雜,我一時(shí)半會(huì)也搞不明白咋回事,據(jù)說是grep會(huì)開子進(jìn)程,并非grep那個(gè)子進(jìn)程,而是開了一個(gè)與腳本相同的進(jìn)程,導(dǎo)致出現(xiàn)問題,具體參考:linux shell腳本執(zhí)行命令時(shí)創(chuàng)建子進(jìn)程問題(特定的情況,例如后臺(tái)運(yùn)行、管道、分支或子shell等,腳本可能會(huì)創(chuàng)建子進(jìn)程執(zhí)行命令)grep)

后來我改用pgrep指令,用這個(gè)命令的好處是,不用使用grep命令了,它直接找出來就是進(jìn)程號(hào),而且不會(huì)帶入額外的進(jìn)程號(hào),下面我們來看下pgrep指令的具體用法。

pgrep指令

pgrep命令用于根據(jù)進(jìn)程的名稱或其他屬性來查找和列出匹配的進(jìn)程ID(PID)。它可以根據(jù)不同的選項(xiàng)進(jìn)行靈活的進(jìn)程查找和過濾。

help文檔

root@ubuntu:/ky/boot# pgrep --help

Usage:
 pgrep [options] <pattern>

Options:
 -d, --delimiter <string>  specify output delimiter
 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line
 -v, --inverse             negates the matching
 -w, --lightweight         list all TID
 -c, --count               count of matching processes
 -f, --full                use full process name to match
 -g, --pgroup <PGID,...>   match listed process group IDs
 -G, --group <GID,...>     match real group IDs
 -i, --ignore-case         match case insensitively
 -n, --newest              select most recently started
 -o, --oldest              select least recently started
 -P, --parent <PPID,...>   match only child processes of the given parent
 -s, --session <SID,...>   match session IDs
 -t, --terminal <tty,...>  match by controlling terminal
 -u, --euid <ID,...>       match by effective IDs
 -U, --uid <ID,...>        match by real IDs
 -x, --exact               match exactly with the command name
 -F, --pidfile <file>      read PIDs from file
 -L, --logpidfile          fail if PID file is not locked
 -r, --runstates <state>   match runstates [D,S,Z,...]
 --ns <PID>                match the processes that belong to the same
                           namespace as <pid>
 --nslist <ns,...>         list which namespaces will be considered for
                           the --ns option.
                           Available namespaces: ipc, mnt, net, pid, user, uts

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see pgrep(1).

中文翻譯:

root@ubuntu:/ky/boot# pgrep --help

用法:
 pgrep [選項(xiàng)] <模式>

選項(xiàng):
 -d, --delimiter <字符串>  指定輸出分隔符
 -l, --list-name           列出PID和進(jìn)程名稱
 -a, --list-full           列出PID和完整命令行
 -v, --inverse             反轉(zhuǎn)匹配結(jié)果
 -w, --lightweight         列出所有TID
 -c, --count               統(tǒng)計(jì)匹配進(jìn)程的數(shù)量
 -f, --full                使用完整進(jìn)程名稱進(jìn)行匹配
 -g, --pgroup <PGID,...>   匹配指定的進(jìn)程組ID
 -G, --group <GID,...>     匹配真實(shí)組ID
 -i, --ignore-case         不區(qū)分大小寫進(jìn)行匹配
 -n, --newest              選擇最近啟動(dòng)的進(jìn)程
 -o, --oldest              選擇最早啟動(dòng)的進(jìn)程
 -P, --parent <PPID,...>   僅匹配給定父進(jìn)程的子進(jìn)程
 -s, --session <SID,...>   匹配會(huì)話ID
 -t, --terminal <tty,...>  通過控制終端進(jìn)行匹配
 -u, --euid <ID,...>       通過有效ID進(jìn)行匹配
 -U, --uid <ID,...>        通過真實(shí)ID進(jìn)行匹配
 -x, --exact               精確匹配命令名稱
 -F, --pidfile <文件>      從文件中讀取PID
 -L, --logpidfile          如果PID文件未鎖定,則失敗
 -r, --runstates <狀態(tài)>    匹配運(yùn)行狀態(tài) [D,S,Z,...]
 --ns <PID>                匹配與<pid>相同命名空間的進(jìn)程
 --nslist <ns,...>         列出將用于--ns選項(xiàng)的命名空間
                           可用的命名空間:ipc, mnt, net, pid, user, uts

 -h, --help     顯示此幫助信息并退出
 -V, --version  輸出版本信息并退出

更多詳細(xì)信息請參閱pgrep(1)

請注意,上面的<pattern>是要匹配的進(jìn)程名稱或其他屬性的模式。可以根據(jù)實(shí)際情況替換為具體的值。

使用示例

以下是pgrep命令不同選項(xiàng)的使用示例:

我們在這個(gè)容器中測試:

注意:我們首先要學(xué)會(huì)區(qū)分什么是進(jìn)程的進(jìn)程名!
進(jìn)程名就是那個(gè)進(jìn)程的可執(zhí)行文件,進(jìn)程名只有一個(gè),除去進(jìn)程名,其他的都是路徑和參數(shù)。
比如/bin/bash /usr/local/bin/entrypoint.sh,進(jìn)程名是bash

root@5940438e0ee6:/build/libevent# echo "=====輸出所有進(jìn)程完整進(jìn)程信息:"
=====輸出所有進(jìn)程完整進(jìn)程信息:
root@5940438e0ee6:/build/libevent# ps -ef 
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 Jun27 pts/0    00:00:00 /bin/bash /usr/local/bin/entrypoint.sh
root           7       1  0 Jun27 pts/0    00:02:56 ./kyai_rest
root          43       0  0 23:38 pts/1    00:00:00 /bin/bash
root          56      43  0 23:40 pts/1    00:00:00 ps -ef
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# echo "輸出所有進(jìn)程進(jìn)程名:"
=====輸出所有進(jìn)程進(jìn)程名:
root@5940438e0ee6:/build/libevent# ps -e -o comm=
bash
kyai_rest
bash
ps
root@5940438e0ee6:/build/libevent# 
1. 列出匹配進(jìn)程的PID和進(jìn)程名稱(-l)(默認(rèn)只能從進(jìn)程名的子集字符串匹配,如果要使用完整進(jìn)程名的子集字符串匹配,請加-f參數(shù),下同)
pgrep -l <pattern>
pgrep --list-name <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -l ky
7 kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -l ./
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -l ./ky
root@5940438e0ee6:/build/libevent#
root@5940438e0ee6:/build/libevent# pgrep -l -f ./ky
7 kyai_rest

2. 列出匹配進(jìn)程的PID和完整的命令行(-a)
pgrep -a <pattern>
pgrep --list-full <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a ky
7 ./kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a ./ky
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a -f ./ky
7 ./kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -af ./ky
7 ./kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a bash
1 /bin/bash /usr/local/bin/entrypoint.sh
43 /bin/bash
root@5940438e0ee6:/build/libevent# 

3. 統(tǒng)計(jì)匹配進(jìn)程的數(shù)量(-c)
pgrep -c <pattern>
pgrep --count <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -c ky
1
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -c bash
2
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -c ./ky
0
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -c -f ./ky
1
root@5940438e0ee6:/build/libevent# 

4. 使用完整的進(jìn)程名稱(包括參數(shù))的子集進(jìn)行匹配(-f)(如果pattern跨越進(jìn)程命令與參數(shù),需要用雙引號(hào)括起來)★★★★★
pgrep -f <pattern>
pgrep --full <pattern>

比如有一個(gè)進(jìn)程全名為python3 -u /ky/alg/kyai/nv/m/people/alg/main.py,用:

pgrep -f <pattern>

pattern為進(jìn)程全名的任意字符串子集,都能匹配到。

示例1
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -f ky
7
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -f ./ky
7
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep ./ky
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep /usr/local/bin/entrypoint.sh
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -f /usr/local/bin/entrypoint.sh
1
root@5940438e0ee6:/build/libevent# 

示例2

pgrep,linux,shell,linux,運(yùn)維

5. 不區(qū)分大小寫進(jìn)行匹配(-i)
pgrep -i <pattern>
pgrep --ignore-case <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -i KyAi
7
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -i entry
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -i -f eNtry
1
root@5940438e0ee6:/build/libevent# 

6. 選擇最近啟動(dòng)的進(jìn)程(n)
pgrep -n <pattern>
pgrep --newest <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a bash
1 /bin/bash /usr/local/bin/entrypoint.sh
43 /bin/bash
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a -n bash
43 /bin/bash
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -n bash
43
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# 

7. 選擇最早啟動(dòng)的進(jìn)程(-o)
pgrep -o <pattern>
pgrep --oldest <pattern>

示例:

root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a bash
1 /bin/bash /usr/local/bin/entrypoint.sh
43 /bin/bash
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -a -o bash
1 /bin/bash /usr/local/bin/entrypoint.sh
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -o bash
1
root@5940438e0ee6:/build/libevent# 

8. 僅匹配給定父進(jìn)程的子進(jìn)程(-P)
pgrep -P <PPID> <pattern>
pgrep --parent <PPID> <pattern>

示例:

比如0號(hào)進(jìn)程有1號(hào)何2號(hào)兩個(gè)子進(jìn)程:

pgrep,linux,shell,linux,運(yùn)維

pgrep -P 0能將0號(hào)進(jìn)程的子進(jìn)程找出來:

root@ubuntu:~# 
root@ubuntu:~# pgrep -P 0
1
2
root@ubuntu:~# 

在查找到時(shí)對(duì)子進(jìn)程篩選:

root@ubuntu:~# 
root@ubuntu:~# pgrep -P 0 "system"
1
root@ubuntu:~# 
root@ubuntu:~# pgrep -P 0 "thread"
2
root@ubuntu:~# 
root@ubuntu:~# 

注意:有時(shí)用-f參數(shù)從非進(jìn)程名的字符串段匹配篩選時(shí),注意雙引號(hào)的使用,以及使用雙引號(hào)后,仍應(yīng)注意的問題:

下面測試中:pgrep -f -P 0 --systempgrep -f -P 0 "--system"都是報(bào)錯(cuò)的,只有pgrep -f -P 0 " --system"沒出問題。

root@ubuntu:~# 
root@ubuntu:~# pgrep -f -P 0 --system
pgrep: unrecognized option '--system'

Usage:
 pgrep [options] <pattern>

Options:
 -d, --delimiter <string>  specify output delimiter
 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line
 -v, --inverse             negates the matching
 -w, --lightweight         list all TID
 -c, --count               count of matching processes
 -f, --full                use full process name to match
 -g, --pgroup <PGID,...>   match listed process group IDs
 -G, --group <GID,...>     match real group IDs
 -i, --ignore-case         match case insensitively
 -n, --newest              select most recently started
 -o, --oldest              select least recently started
 -P, --parent <PPID,...>   match only child processes of the given parent
 -s, --session <SID,...>   match session IDs
 -t, --terminal <tty,...>  match by controlling terminal
 -u, --euid <ID,...>       match by effective IDs
 -U, --uid <ID,...>        match by real IDs
 -x, --exact               match exactly with the command name
 -F, --pidfile <file>      read PIDs from file
 -L, --logpidfile          fail if PID file is not locked
 -r, --runstates <state>   match runstates [D,S,Z,...]
 --ns <PID>                match the processes that belong to the same
                           namespace as <pid>
 --nslist <ns,...>         list which namespaces will be considered for
                           the --ns option.
                           Available namespaces: ipc, mnt, net, pid, user, uts

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see pgrep(1).
root@ubuntu:~# 
root@ubuntu:~# pgrep -f -P 0 "--system"
pgrep: unrecognized option '--system'

Usage:
 pgrep [options] <pattern>

Options:
 -d, --delimiter <string>  specify output delimiter
 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line
 -v, --inverse             negates the matching
 -w, --lightweight         list all TID
 -c, --count               count of matching processes
 -f, --full                use full process name to match
 -g, --pgroup <PGID,...>   match listed process group IDs
 -G, --group <GID,...>     match real group IDs
 -i, --ignore-case         match case insensitively
 -n, --newest              select most recently started
 -o, --oldest              select least recently started
 -P, --parent <PPID,...>   match only child processes of the given parent
 -s, --session <SID,...>   match session IDs
 -t, --terminal <tty,...>  match by controlling terminal
 -u, --euid <ID,...>       match by effective IDs
 -U, --uid <ID,...>        match by real IDs
 -x, --exact               match exactly with the command name
 -F, --pidfile <file>      read PIDs from file
 -L, --logpidfile          fail if PID file is not locked
 -r, --runstates <state>   match runstates [D,S,Z,...]
 --ns <PID>                match the processes that belong to the same
                           namespace as <pid>
 --nslist <ns,...>         list which namespaces will be considered for
                           the --ns option.
                           Available namespaces: ipc, mnt, net, pid, user, uts

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see pgrep(1).
root@ubuntu:~# 
root@ubuntu:~# 
root@ubuntu:~# pgrep -f -P 0 " --system"
1
root@ubuntu:~# 
root@ubuntu:~# 

9. 通過控制終端進(jìn)行匹配(-t)
用途

指定特定終端名稱進(jìn)行搜索的用途之一是限定搜索范圍。在多用戶或多終端環(huán)境中,可能會(huì)有多個(gè)終端同時(shí)運(yùn)行著相同的進(jìn)程。通過指定終端名稱,你可以僅在特定終端中搜索匹配的進(jìn)程,而不是在所有終端中搜索。

這對(duì)于需要在特定終端上執(zhí)行操作或監(jiān)控特定終端上的進(jìn)程非常有用。例如,你可能希望在某個(gè)特定的終端上查找正在運(yùn)行的某個(gè)應(yīng)用程序的進(jìn)程,或者在某個(gè)特定的終端上查找與某個(gè)用戶相關(guān)的進(jìn)程。

另外,指定終端名稱還可以用于在腳本或自動(dòng)化任務(wù)中進(jìn)行進(jìn)程管理。通過指定特定的終端,你可以確保只對(duì)特定終端上的進(jìn)程進(jìn)行操作,而不會(huì)影響其他終端上的進(jìn)程。

總而言之,指定特定終端名稱進(jìn)行搜索可以提供更精確和有針對(duì)性的進(jìn)程查找和管理。

命令
pgrep -t <tty> <pattern>
pgrep --terminal <tty> <pattern>
測試步驟

按照以下步驟進(jìn)行測試:

  1. 打開終端。
  2. 運(yùn)行 tty 命令,獲取當(dāng)前終端的名稱。例如,如果終端名稱是 /dev/tty1,則將 <tty> 替換為 tty1
  3. 運(yùn)行 pgrep -t <tty> <pattern> 命令,將 <pattern> 替換為你想要查找的進(jìn)程名稱或關(guān)鍵字。例如,如果你想要查找所有運(yùn)行著的 bash 進(jìn)程,可以運(yùn)行 pgrep -t tty1 bash。
  4. 如果命令成功執(zhí)行,它將輸出匹配的進(jìn)程 ID。
  5. 你也可以嘗試運(yùn)行 pgrep --terminal <tty> <pattern> 命令,它與上述命令的作用相同。

請注意,pgrep 命令用于在進(jìn)程列表中查找匹配的進(jìn)程,并輸出它們的進(jìn)程 ID。<tty> 是終端名稱,<pattern> 是要查找的進(jìn)程名稱或關(guān)鍵字。你需要根據(jù)你的實(shí)際情況替換這些參數(shù)。

示例
root@ubuntu:~# 
root@ubuntu:~# tty
/dev/pts/0
root@ubuntu:~# 
root@ubuntu:~# 
root@ubuntu:~# pgrep -t /dev/pts/0 bash
root@ubuntu:~# 
root@ubuntu:~# pgrep -t /dev/pts/0 sy
root@ubuntu:~# 
root@ubuntu:~# pgrep -t /dev/pts/0
root@ubuntu:~# 
root@ubuntu:~# pgrep -t "/dev/pts/0"
root@ubuntu:~# 
root@ubuntu:~# pgrep -t "/dev/pts/0" bash
root@ubuntu:~# 
root@ubuntu:~# 

尷尬,我這啥也搜不出來

10. 通過有效ID進(jìn)行匹配(-u)
用途

pgrep -u <ID> <pattern>pgrep --euid <ID> <pattern> 命令用于在指定用戶 ID 或有效用戶 ID 下查找匹配的進(jìn)程。

  • <ID> 參數(shù)用于指定用戶 ID 或有效用戶 ID。你可以使用用戶的用戶名或用戶 ID 來替換 <ID>
  • <pattern> 參數(shù)用于指定要查找的進(jìn)程名稱或關(guān)鍵字。
命令
pgrep -u <ID> <pattern>
pgrep --euid <ID> <pattern>
測試步驟
  1. 打開終端。
  2. 運(yùn)行 id 命令,獲取當(dāng)前用戶的用戶 ID 和有效用戶 ID。例如,如果用戶 ID 是 1000,有效用戶 ID 是 1000,則將 <ID> 替換為 1000。
  3. 運(yùn)行 pgrep -u <ID> <pattern> 命令,將 <pattern> 替換為你想要查找的進(jìn)程名稱或關(guān)鍵字。例如,如果你想要查找當(dāng)前用戶下所有運(yùn)行著的 bash 進(jìn)程,可以運(yùn)行 pgrep -u 1000 bash
  4. 如果命令成功執(zhí)行,它將輸出匹配的進(jìn)程 ID。
  5. 你也可以嘗試運(yùn)行 pgrep --euid <ID> <pattern> 命令,它與上述命令的作用相同。

請注意,pgrep 命令用于在進(jìn)程列表中查找匹配的進(jìn)程,并輸出它們的進(jìn)程 ID。-u--euid 選項(xiàng)用于指定用戶 ID 或有效用戶 ID。<ID> 是用戶 ID 或有效用戶 ID,<pattern> 是要查找的進(jìn)程名稱或關(guān)鍵字。你需要根據(jù)你的實(shí)際情況替換這些參數(shù)。

示例
root@ubuntu:~# 
root@ubuntu:~# id
uid=0(root) gid=0(root) groups=0(root)
root@ubuntu:~# 
root@ubuntu:~# 
root@ubuntu:~# pgrep -u 0000 bash
3058
3955
23187
root@ubuntu:~# 
root@ubuntu:~# pgrep -u 0 bash
3058
3955
23187
root@ubuntu:~# 
root@ubuntu:~# pgrep -u 1000 bash
root@ubuntu:~# 
root@ubuntu:~# ps -ef | grep bash
root        1061       1  0 19:27 ?        00:00:00 /bin/bash /etc/systemd/nvmemwarning.sh
root        1260       1  0 19:28 ?        00:00:00 /bin/bash /ky/boot/kyai_nv_server.sh
root        1276       1  0 19:28 ?        00:00:00 /bin/bash /etc/systemd/nvgetty.sh
root        3058    2914  0 19:28 pts/0    00:00:00 /bin/bash /usr/local/bin/entrypoint.sh
root        3955    3915  0 19:28 pts/0    00:00:00 /bin/bash /usr/local/bin/entrypoint.sh
root       23187   23106  0 21:46 pts/0    00:00:00 -bash
root       36607   23187  0 23:39 pts/0    00:00:00 grep --color=auto bash
root@ubuntu:~# 
root@ubuntu:~# 

pgrep,linux,shell,linux,運(yùn)維

11. 通過真實(shí)ID進(jìn)行匹配(-U)

具體請參見有效id和真實(shí)id,我目前還不是很理解。

命令
pgrep -U <ID> <pattern>
pgrep --uid <ID> <pattern>
示例
root@ubuntu:~# 
root@ubuntu:~# pgrep -U 0000 bash
3058
3955
23187
root@ubuntu:~# 
root@ubuntu:~# 

12. 精確匹配命令名稱(-x)★★★
命令
pgrep -x <pattern>
pgrep --exact <pattern>
示例
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# ps -ef 
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 19:28 pts/0    00:00:00 /bin/bash /usr/local/bin/entrypoint.sh
root           8       1  0 19:28 pts/0    00:00:39 ./kyai_rest
root          41       0  0 23:45 pts/1    00:00:00 /bin/bash
root          54      41  0 23:46 pts/1    00:00:00 ps -ef
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x kyai 
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x kyai_rest
8
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f kyai_rest
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f ./kyai_rest
8
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x bash          
1
41
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f bash
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f /bin/bash
41
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f /bin/bash /usr/local/bin/entrypoint.sh
pgrep: only one pattern can be provided
Try `pgrep --help' for more information.
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# pgrep -x -f "/bin/bash /usr/local/bin/entrypoint.sh"
1
root@5940438e0ee6:/build/libevent# 
root@5940438e0ee6:/build/libevent# 

注意:精準(zhǔn)匹配,是包含參數(shù)的所有完整匹配

pgrep,linux,shell,linux,運(yùn)維文章來源地址http://www.zghlxwxcb.cn/news/detail-734107.html

到了這里,關(guān)于linux shell pgrep命令使用方法(pgrep指令)獲取進(jìn)程號(hào)、統(tǒng)計(jì)進(jìn)程數(shù)量(學(xué)會(huì)區(qū)分Linux進(jìn)程進(jìn)程名)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Linux命令行工具使用HTTP代理的方法詳解

    Linux命令行工具使用HTTP代理的方法詳解

    親愛的Linux用戶們,有沒有想過在命令行世界里,你的每一個(gè)指令都能悄無聲息地穿越千山萬水,而不被外界窺探?哈哈,沒錯(cuò),就是通過HTTP代理!今天,我們就來一起探索如何在Linux命令行工具中使用HTTP代理,讓你的指令行走江湖更加神秘莫測! 一、設(shè)置環(huán)境變量 首先,

    2024年04月24日
    瀏覽(24)
  • linux下tar命令的壓縮和解壓詳細(xì)使用方法

    在Linux系統(tǒng)中, tar 命令用于創(chuàng)建、查看、提取和解壓 tar 存檔文件。以下是 tar 命令的一些常見用法: 壓縮文件或目錄: 選項(xiàng)說明: -c : 創(chuàng)建新的歸檔文件 -z : 使用 gzip 格式壓縮/解壓縮 -j : 使用 bzip2 格式壓縮/解壓縮 -J : 使用 xz 格式壓縮/解壓縮 -v : 顯示詳細(xì)信息 -f : 指定歸

    2024年04月27日
    瀏覽(35)
  • linux ssh上傳下載文件命令SCP使用方法

    在linux環(huán)境里,我們從服務(wù)器上下載或者從本地上傳文件到服務(wù)器上可以通過 SCP命令 來實(shí)現(xiàn)。 SCP即Security Copy,是基于SSH登錄實(shí)現(xiàn)的遠(yuǎn)程文件拷貝命令 。 命令參數(shù): -r: 遞歸復(fù)制整個(gè)文件夾 -i :詢問是否覆蓋 -p :保留文件 具體使用方法如下: scp 本地文件路徑 用戶名@ServerIP:

    2024年02月16日
    瀏覽(28)
  • linux下下載文件的常用命令wget,curl等使用方法及使用示例

    linux下下載文件的常用命令wget,curl等使用方法及使用示例

    在 Linux 操作系統(tǒng)中,有許多下載文件的工具可供選擇。這些工具包括命令行工具和圖形界面工具,每個(gè)工具都有其自身的特點(diǎn)和用途。以下是一些常用的下載文件工具: wget :一個(gè)功能強(qiáng)大的命令行下載工具,支持 HTTP、HTTPS、FTP 等協(xié)議,能夠斷點(diǎn)續(xù)傳、遞歸下載等。 curl :

    2024年04月17日
    瀏覽(56)
  • 【linux命令講解大全】076.pgrep命令:查找和列出符合條件的進(jìn)程ID

    根據(jù)用戶給出的信息在當(dāng)前運(yùn)行進(jìn)程中查找并列出符合條件的進(jìn)程ID(PID) 補(bǔ)充說明 pgrep 命令以名稱為依據(jù)從運(yùn)行進(jìn)程隊(duì)列中查找進(jìn)程,并顯示查找到的進(jìn)程ID。每一個(gè)進(jìn)程ID以一個(gè)十進(jìn)制數(shù)表示,通過一個(gè)分割字符串和下一個(gè)ID分開,默認(rèn)的分割字符串是一個(gè)新行。對(duì)于每個(gè)

    2024年02月09日
    瀏覽(46)
  • 深入篇【Linux】學(xué)習(xí)必備:Shell命令運(yùn)行原理 + 基本指令

    Linux嚴(yán)格意義上來說是一個(gè)操作系統(tǒng),我們稱為\\\"核心\\\",但我們一般用戶,是不能直接使用這個(gè)\\\"核心\\\"。而是通過\\\"核心\\\"的外殼程序,也就是所謂的Shell來與\\\"核心\\\"溝通。 其實(shí)我們所有的指令都要在OS內(nèi)部運(yùn)行,但是OS使用的難道太高,我們用戶很難直接與OS打交道。 從技術(shù)角度

    2024年02月07日
    瀏覽(25)
  • 【linux命令講解大全】073.“Linux文件搜索工具:bzgrep和egrep的使用方法“

    使用正則表達(dá)式搜索 .bz2 壓縮包中的文件。 補(bǔ)充說明 bzgrep 命令用于在 .bz2 壓縮包中搜索符合正則表達(dá)式的內(nèi)容,并將匹配的行輸出到標(biāo)準(zhǔn)輸出。 語法 參數(shù) pattern : 指定要搜索的模式。 bz2_file : 指定要搜索的 .bz2 壓縮包。 在文件內(nèi)查找指定的字符串。 補(bǔ)充說明 egrep 命令用于

    2024年02月09日
    瀏覽(25)
  • 【linux命令講解大全】106.使用eject命令退出抽取式設(shè)備的方法和選項(xiàng)

    用來退出抽取式設(shè)備 eject 命令用來退出抽取式設(shè)備。若設(shè)備已掛入,則 eject 命令會(huì)先將該設(shè)備卸除再退出。 eject 允許可移動(dòng)介質(zhì)(典型是cd-ROM、軟盤、磁帶、或者JAZ以及zip磁盤)在軟件控制下彈出。該命令也可以控制一些多盤片CD-ROM控制器,控制一些設(shè)備支持的自動(dòng)彈出功

    2024年02月08日
    瀏覽(24)
  • linux usermod命令、groupmod命令使用方法(bad names(不良名稱))(GECOS field(GECOS字段))

    usermod 命令用于修改用戶賬戶的屬性。它可以用來修改用戶的用戶名、用戶ID、用戶組ID、用戶家目錄、用戶登錄Shell等屬性。例如,要將用戶的登錄Shell修改為 /bin/bash ,可以使用以下命令: 其中, username 是要修改的用戶的用戶名。 翻譯: 什么是bad names(不良名稱)? \\\"bad n

    2024年02月12日
    瀏覽(23)
  • java:獲取本機(jī)IP,Linux環(huán)境下使用InetAddress.getLocalHost()方法獲得127.0.0.1

    java:獲取本機(jī)IP,Linux環(huán)境下使用InetAddress.getLocalHost()方法獲得127.0.0.1

    知道InetAddress.getLocalHost()方法是可以獲取本地ip的,但是在mac電腦上執(zhí)行的時(shí)候,偶爾會(huì)得到127.0.0.1的輸出,這樣拿到本地ip很不穩(wěn)定,感覺就很不靠譜了 代碼 mac上輸出 在 windows環(huán)境 : 使用InetAddress.getLocalHost()方法看似正常能獲得本地ip,實(shí)際也有不確定性( 多網(wǎng)卡協(xié)同工作環(huán)

    2024年02月01日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包