Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux / Bash, using ps -o to get process by specific name?

I am trying to use the ps -o command to get just specific info about processes matching a certain name. However, I am having some issues on this, when I try to use this even to just get all processes, like so, it just returns a subset of what a normal ps -ef would return (it doesn't return nearly the same number of results so its not returning all running processes)

ps -ef -o pid,time,comm 

I want to try something like this (below) but incorporate the ps -o to just get specific info from it (just the PID)

ps -ef |grep `whoami`| grep firefox-bin 

Any advice is appreciated as to how to do this properly, thanks

like image 684
Rick Avatar asked Sep 24 '10 20:09

Rick


People also ask

How do I find the process ID of a particular process?

A PID is automatically assigned to each process when it is created. A process is nothing but running instance of a program and each process has a unique PID on a Unix-like system. The easiest way to find out if process is running is run ps aux command and grep process name.

Which command enables you to find a specific process?

You can use the ps command to find out which processes are running and display information about those processes. The ps command has several flags that enable you to specify which processes to list and what information to display about each process.

How do I list processes owned by a specific user?

To see only the processes owned by a specific user on Linux run: ps -u {USERNAME} Search for a Linux process by name run: pgrep -u {USERNAME} {processName} Another option to list processes by name is to run either top -U {userName} or htop -u {userName} commands.


2 Answers

This will get you the PID of a process by name:

pidof name 

Which you can then plug back in to ps for more detail:

ps -p $(pidof name) 
like image 183
Alex Howansky Avatar answered Sep 28 '22 02:09

Alex Howansky


This is a bit old, but I guess what you want is: ps -o pid -C PROCESS_NAME, for example:

ps -o pid -C bash 

EDIT: Dependening on the sort of output you expect, pgrep would be more elegant. This, in my knowledge, is Linux specific and result in similar output as above. For example:

pgrep bash 
like image 28
h7r Avatar answered Sep 28 '22 01:09

h7r