What do you do when a Linux info center server is running slowly? One particular of the to start with factors you may well do is check out a community connection. Just after that, you’re likely likely to need to uncover out what products and services/software program have long gone rogue and are gobbling up important procedure means. There are a number of strategies to do that. For example, you could concern the prime command, which will listing out, in real-time, running processes. From there you can uncover a process ID and see how substantially memory utilization claimed process is using.
Or you can go a further route and use a couple of instructions to uncover that Approach ID (PID) by title. There are two instructions in individual, both of those of which each individual Linux administrator should know. I want to demonstrate the utilization of all those instructions, so with any luck , your Linux admin career may well be a bit a lot easier. I’ll be demonstrating on Ubuntu Server 18.04, but the instructions are offered (and are used in the identical vogue) on all Linux platforms.
The pidof command is the to start with we’ll glimpse at. As you may well be expecting, it will notify us the PID of a company. This command is located on your Linux servers out of the box, so you will find no need to set up anything at all.
Let’s say you have a LAMP server in your info center and Apache is behaving poorly (or at minimum you believe it is). To troubleshoot, you may well need to uncover the PID of Apache. The good thing is, you have the pidof command, so you could concern:
In the situation of Apache, you may well be returned a number of PIDs (Determine A).
You now have each individual Approach ID of your at this time running Apache server. Of study course, with a process like Apache, on the off chance it is behaving, you may well want to do a swift restart using a command like sudo systemctl restart apache2. But if the company won’t answer to a restart, what do you do? The good thing is, you have all those PIDs, so you can always kill the company (using the kill PID command, where by PID is the PID of the company to be killed). Killing a company like Apache should be accomplished only as a very last vacation resort (always start with a tool like systemctl). But having all those PIDs in hand can make your career substantially a lot easier.
SEE: Linux distribution comparison chart (Tech Pro Research)
The pgrep command capabilities in similar vogue to pidof, the most important variation getting that it can glimpse up a process dependent on a title or other attributes. For example, pgrep can glimpse up PIDs related with a group. On Ubuntu, most Apache content material tends to be hooked up to the www-info group. With pgrep, it can be straightforward to uncover out what PIDs are related with that group. Situation the command:
pgrep -G www-info
The output of the earlier mentioned command will listing all the PIDs that belong to the group in query (Determine B).
The output of that command may well not do us any excellent. Just after all, how do we know what all those PIDs belong to (outdoors of a group)? We may well need to know not only the PIDs for the group, but the products and services hooked up to the PIDs. To get this information and facts, we increase the -l option like this:
pgrep -l -G www-info
Now we see the PIDs and the products and services listed (Determine C).
SEE: How to uncover documents in Linux with grep: ten examples (absolutely free TechRepublic PDF)
You could also use pgrep to listing a process by user. If you issued the command pgrep -U root, you would see each individual PID that belonged to the root user (which would be a major number). If you issued that identical command using a certain user (other than root), possibilities are the listing would be substantially shorter. For occasion, pgrep -U jack (on my server) returns the PIDs:
1225 1234 1251 1352
To uncover out what products and services are related with all those PIDs, concern the command:
pgrep -l -U jack
Now we see what products and services and PIDs belong to the user jack (Determine D).
You can find additional to pidof and pgrep than I have outlined in this article. The most effective way to learn additional is by issuing the instructions guy pidof and guy pgrep to read through the handbook web pages for each command. These two instructions should simply in shape in your Linux admin toolbox and will support keep your info center buzzing.