I need to try and find the ProcessId of a process.

Initially I was doing:

appPid=$(pidof -x $application)

This worked fine.

However, it now turns out that the applictaion could run from a variety of locations, such as:

/home/user/desktop/link to apps/appName.app

So I tried to simply do

appPid=$(pidof -x $application) 

But this didn't find any matches. I assume that pidof requires a full path to match.

How else can I get the ProcessId?

I think I need to further explain.

If I do

ps aux | grep application.app

I get two results.

user 29912 . . . . /home/user/apps/application.app
user 12345 . . . . grep application.app

If I then do

var1=`pgrep application.app`
echo $var1

the result is blank. It should be 29912.

  • 1
    What if you do pgrep -f application.app?
    – muru
    Jan 13 '16 at 10:00
  • That looks like it works. cheers
    – IGGt
    Jan 13 '16 at 10:05

The pgrep itself returns the process ids. Use:

     $pgrep <process_name>

     $pgrep bash

If you want the output to store in variable:

   var1=`pgrep <appname>`

  pids=`pgrep bash`
  echo $pids
  3896 4013 4115

I would use the following:

appPid=$(pgrep $application)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.