In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article "linux how to use pid to check whether the process exists" article knowledge point most people do not understand, so Xiaobian to give you a summary of the following content, detailed content, clear steps, has a certain reference value, I hope you can read this article to gain something, let's take a look at this article "linux how to use pid to check whether the process exists" article bar.
In linux, you can use the kill command to check whether the process exists according to pid."kill -0" does not send a signal to the process, but it will check for errors. If the process exists, the result returned is 0. If the process does not exist, the result returned is 1. The syntax is "kill -0 pid".
Operating environment: Linux 7.3 system, Dell G3 computer.
How to use PID to check whether the process exists
Suppose we now want to check if a process is alive once a minute. To do this, we would run ps once a minute and do a grep regular lookup. This overhead may not seem like much on the server, but what if we were monitoring dozens or hundreds of such processes simultaneously on the same node? Therefore, we need to explore some better ways from a performance point of view.
Daemon processes usually have their own pid or lock files, and we can check whether these files exist to determine whether the process exists. However, there are exceptions where pid files exist but processes do not. Therefore, you cannot rely on the process pid file to detect whether the process is alive.
A reliable method is to use "kill -0 pid", kill -0 does not send any signals to the process, but does error checking. The command returns 0 if the process exists and 1 if it does not.
However, this method can only be used by ordinary users to check their own processes, because sending a signal to other users 'processes will cause an error because they have no permissions, and the return value will also be 1.
[sw@gentoo ~]$ kill 2993-bash: kill: (2993) - Operation not permitted[sw@gentoo ~]$ echo $? 1[sw@gentoo ~]$
Of course, if you execute the kill command as a privileged user, there are no permissions issues.
On the other hand, we know that the kernel exports information about running processes on the system through the/proc virtual file system, and each process has a/proc/directory. So we can convert detecting the presence of a process to detecting the presence of the/proc/directory, which is much simpler.
The above is about "linux how to use pid to check whether the process exists" the content of this article, I believe everyone has a certain understanding, I hope the content shared by Xiaobian is helpful to everyone, if you want to know more related knowledge content, please pay attention to 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.