In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use the grep command to match under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
The grep command looks for a process by name from the running process queue and displays the process id found. Each process ID is represented as a decimal number, separated by a split string from the next ID, and the default split string is a new line. For each attribute option, the user can specify a collection of possible values separated by commas on the command line.
Pgrep command: ps-eo pid,cmd | awk'{print $1 recording 2}'| grep KeyWord parameter description: option description-d defines the separator between multiple processes, and newline characters are used if not defined. -P finds the pid-n of all word processes according to the parent process PID, which means that if the program has more than one process running, it only looks for the latest, that is, the last one started. -o means that if the program has more than one process running, it only looks for the oldest, that is, the first to start (the parent process PID when there are multiple processes). -G is followed by a set of group id, which only considers the processes in the group list when searching. The-u is followed by a set of valid users ID (effetive user id), which only considers the processes in the effective user list when searching. The-U is followed by a set of actual users ID (real user id), which only considers the processes in the real user list when searching. -x means that the name of the process must match exactly, and all of the above options can be partially matched. -l will print not only the pid, but also the process name. -f is generally used in conjunction with-l to print the parameters of the process.
Show details
Using the example defaults to displaying only PIDroot@361way:~# pgrep zabbix238023812382238323842385-l showing both PID and ProcessNameroot@361way:~# pgrep-l zabbix2380 zabbix_agentd2381 zabbix_agentd2382 zabbix_agentd2383 zabbix_agentd2384 zabbix_agentd2385 zabbix_agentd-o when matching multiple processes, showing the root@361way:~# pgrep-l-o zabbix2380 zabbix_agentd-n with the lowest process number, and showing the root@361way:~# pgrep-l-n zabbix2385 zabbix_agentd with the largest process number when matching multiple processes.
It should be noted that by default, pgrep can only match the first 15 strings of a process. Individuals can refer to the instructions in ubuntu Q & A, as follows:
Ps aux includes the full command line (path and parameters), while pgrep only looks at the first 15 characters of the executable's names special parameters
You can use pgrep-f to match all characters in a process, as shown in the following example:
/ / you can use the ps command to normally grep to the process root@361way:~# ps auxf | grep druidroot 25713 0.0 8108 940 pts/0 S+ 06:08 0:00 _ grep-- color=auto druiddev 7438 1.3 11.5 5524888 884988? Sl Jun16 672 Xmx4g 54 java-server-Xmx4g-XX:MaxNewSize=1g-XX:+UseCompressedOops-XX:+UseParNewGC-Duser.timezone=UTC-Dfile.encoding=UTF-8-XX:+UseConcMarkSweepGC-XX:+PrintGCDetails-XX:+PrintGCTimeStamps-XX:+UseCMSInitiatingOccupancyOnly-XX:+PrintHeapAtGC-XX:+PrintGCApplicationConcurrentTime-XX:+PrintGCApplicationStoppedTime-Djava.io.tmpdir=/data/tmpdata/java.io.tmpdata-Xloggc:/data/tmpdata/java.io.tmpdata/coordinator-gc.log-classpath lib/*:config/coordinator io.druid.cli.Main server coordinator//pgrep matching knot If it is empty, root@361way:~# pgrep druid// plus-f parameter Normally get the process pidroot@361way:~# pgrep-f druid7438root@361way:~# pgrep-f-l druid7438 java-server-Xmx4g-XX:MaxNewSize=1g-XX:+UseCompressedOops-XX:+UseParNewGC-Duser.timezone=UTC-Dfile.encoding=UTF-8-XX:+UseConcMarkSweepGC-XX:+PrintGCDetails-XX:+PrintGCTimeStamps-XX:+UseCMSInitiatingOccupancyOnly-XX:+PrintHeapAtGC-XX:+PrintGCApplicationConcurrentTime-XX:+PrintGCApplicationStoppedTime-Djava.io.tmpdir=/data/tmpdata/java.io.tmpdata-Xloggc:/data/tmpdata/java.io.tmpdata/coordinator-gc.log-classpath lib / *: config/coordinator io.druid.cli.Main server coordinator
Use the-P parameter to output the child processes of the specified parent process, such as:
Root@361way:~# pgrep-P 238023812382238323842385
The above is all the contents of the article "how to use the grep command to match under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.