How can I only extract PID from a process?

Asked

Viewed 1,651 times

5

My idea is to create a simple script that can search the PID of a process and kill it for example.

This is what I have done so far but has the problem that when running ps the PID will not be extracted.

echo "nome do processo : "
read $matança
ps -ax | grep $matança
  • you could pipe the result of your grep and use another grep to catch only the PID, something like: ps -ax | grep $matança | head -1 | egrep '^\s*[0-9]+' -o (head is because your first grep will end up on the list of processes, and you just want the first). This is just an example to guide you, it’s nothing too robust.

  • See also the command killall ....

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.