How to get only process ID in specify process name in linux? How to get only process ID in specify process name in linux? shell shell

How to get only process ID in specify process name in linux?


You can pipe your output to awk to print just the PID. For example:

ps -ef | grep nginx | awk '{print $2}'9439


You can use:

ps -ef | grep '[j]ava'

Or if pgrep is available then better to use:

pgrep -f java


Use this: ps -C <name> -o pid=