How to display a list of processes running by users whose names begin with a specific character (or string)? For example, with the character "a"?
2 answers
A great team to get exactly process IDs (PIDs) by name is the pgrep command.
The command can be used both to get all the processes running on this OS, and for an individual user (the -u option). Example of use:
pgrep -u user_id искомая_строка If you need to search without case, specify -i before the desired name.
The main application, in my case - for the preparation of scripts in which it is necessary to perform actions with a group of processes. The example below shows how you can urgently shut down the Chrome browser, if it hangs
pgrep -i chrome | xargs kill -9 A similar question: How to view the list of processes from the terminal in Ubuntu?
- Here, the correct answer! - 0andriy
- About pgrep that's right, only the author had a question about the initial letter in the user name, what should he do with it? It is not clear from the answer :) - approximatenumber
- one@approximatenumber Indeed. Apparently not read, after reading the answer. Since the question is rewritten, I think it is worth asking a new one and giving the author of this a link to it. - Nicolas Chabanovsky ♦
The assumption of ps is correct. The first rule is to always read man. From there you can learn the necessary options.
sudo ps -ef Will show all processes of all users in full format. Then you just need to filter those that begin with the letter 'a'
sudo ps -ef | grep '^a.*' Everything.
- onedo not disgrace, please. remove the sudo program call. - aleksandr barakin