How do I determine the path to a binary of a process?












27















Is there a way to find out the directory/disk location a process was started from? I am aware of the /proc mount but not really where to look inside of it.










share|improve this question




















  • 1





    Do you mean the location of the binary, or the directory from which a process started?

    – Lekensteyn
    Jun 16 '11 at 10:59











  • Sorry for the ambiguity, I mean the binary

    – SuperJumbo
    Jun 16 '11 at 11:11
















27















Is there a way to find out the directory/disk location a process was started from? I am aware of the /proc mount but not really where to look inside of it.










share|improve this question




















  • 1





    Do you mean the location of the binary, or the directory from which a process started?

    – Lekensteyn
    Jun 16 '11 at 10:59











  • Sorry for the ambiguity, I mean the binary

    – SuperJumbo
    Jun 16 '11 at 11:11














27












27








27


11






Is there a way to find out the directory/disk location a process was started from? I am aware of the /proc mount but not really where to look inside of it.










share|improve this question
















Is there a way to find out the directory/disk location a process was started from? I am aware of the /proc mount but not really where to look inside of it.







process






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 16 '11 at 12:08









Lekensteyn

123k49270361




123k49270361










asked Jun 16 '11 at 10:47









SuperJumboSuperJumbo

229247




229247








  • 1





    Do you mean the location of the binary, or the directory from which a process started?

    – Lekensteyn
    Jun 16 '11 at 10:59











  • Sorry for the ambiguity, I mean the binary

    – SuperJumbo
    Jun 16 '11 at 11:11














  • 1





    Do you mean the location of the binary, or the directory from which a process started?

    – Lekensteyn
    Jun 16 '11 at 10:59











  • Sorry for the ambiguity, I mean the binary

    – SuperJumbo
    Jun 16 '11 at 11:11








1




1





Do you mean the location of the binary, or the directory from which a process started?

– Lekensteyn
Jun 16 '11 at 10:59





Do you mean the location of the binary, or the directory from which a process started?

– Lekensteyn
Jun 16 '11 at 10:59













Sorry for the ambiguity, I mean the binary

– SuperJumbo
Jun 16 '11 at 11:11





Sorry for the ambiguity, I mean the binary

– SuperJumbo
Jun 16 '11 at 11:11










5 Answers
5






active

oldest

votes


















33














The /proc way would be to inspect the exe link in the directory corresponding to the pid.



Let's take an example with update-notifier:



Find the pid, which is 15421 in this example:



egil@gud:~$ ps x | grep update-notifier
2405 pts/4 S+ 0:00 grep update-notifier
15421 ? Sl 0:00 update-notifier


Look up the symbolic link:



egil@gud:~$ file /proc/15421/exe
/proc/15421/exe: symbolic link to `/usr/bin/update-notifier'





share|improve this answer


























  • Oh yeah, I was almost there. Legend, thank you.

    – SuperJumbo
    Jun 16 '11 at 11:11



















13














Maybe which is what you are looking for. For instance, on my system



which firefox 


returns



/usr/bin/firefox


See also Find Path of Application Running on Solaris, Ubuntu, Suse or Redhat Linux .






share|improve this answer



















  • 6





    which is cool, but it only returns programs in your $PATH. If I run RandomProgramIDownloadedToErisKnowsWhere.bin, this won't be of much use.

    – djeikyb
    Jun 16 '11 at 11:02





















3














Providing you've a process ID available, you can use:



readlink -f /proc/$pid/exe


(replace $pid by the process ID of a process)



If the process is not owned by you, you'll have to put sudo in front of it.



An example for determining the location of the command firefox:





  1. The output of ps ax -o pid,cmd | grep firefox :



    22831 grep --color=auto firefox
    28179 /usr/lib/firefox-4.0.1/firefox-bin



  2. 28179 is the process ID, so you've to run:



    readlink -f /proc/28179/exe


    which outputs:



    /usr/bin/firefox







share|improve this answer





















  • 2





    You can do cool things with /proc/$pid/exe, if the binary is accidentally deleted, you can restore it with: dd if=/proc/$pid/exe of=restored-binary

    – Lekensteyn
    Jun 16 '11 at 11:05



















1














Press Ctrl+Alt+T to go to a terminal and type:



ls -al /proc/{pid}/fd  


and then check the output



This will list all the files your process is associated with...






share|improve this answer


























  • Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-)

    – Fabby
    Jul 4 '18 at 17:05





















0














All the commands in the other answers are good, but you could do even more - seeing how some process has been actually run before it got to the process list.



Run in terminal:



top


And while it is running, press keyboard C and you will get a command of the processes that was run.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f49024%2fhow-do-i-determine-the-path-to-a-binary-of-a-process%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    33














    The /proc way would be to inspect the exe link in the directory corresponding to the pid.



    Let's take an example with update-notifier:



    Find the pid, which is 15421 in this example:



    egil@gud:~$ ps x | grep update-notifier
    2405 pts/4 S+ 0:00 grep update-notifier
    15421 ? Sl 0:00 update-notifier


    Look up the symbolic link:



    egil@gud:~$ file /proc/15421/exe
    /proc/15421/exe: symbolic link to `/usr/bin/update-notifier'





    share|improve this answer


























    • Oh yeah, I was almost there. Legend, thank you.

      – SuperJumbo
      Jun 16 '11 at 11:11
















    33














    The /proc way would be to inspect the exe link in the directory corresponding to the pid.



    Let's take an example with update-notifier:



    Find the pid, which is 15421 in this example:



    egil@gud:~$ ps x | grep update-notifier
    2405 pts/4 S+ 0:00 grep update-notifier
    15421 ? Sl 0:00 update-notifier


    Look up the symbolic link:



    egil@gud:~$ file /proc/15421/exe
    /proc/15421/exe: symbolic link to `/usr/bin/update-notifier'





    share|improve this answer


























    • Oh yeah, I was almost there. Legend, thank you.

      – SuperJumbo
      Jun 16 '11 at 11:11














    33












    33








    33







    The /proc way would be to inspect the exe link in the directory corresponding to the pid.



    Let's take an example with update-notifier:



    Find the pid, which is 15421 in this example:



    egil@gud:~$ ps x | grep update-notifier
    2405 pts/4 S+ 0:00 grep update-notifier
    15421 ? Sl 0:00 update-notifier


    Look up the symbolic link:



    egil@gud:~$ file /proc/15421/exe
    /proc/15421/exe: symbolic link to `/usr/bin/update-notifier'





    share|improve this answer















    The /proc way would be to inspect the exe link in the directory corresponding to the pid.



    Let's take an example with update-notifier:



    Find the pid, which is 15421 in this example:



    egil@gud:~$ ps x | grep update-notifier
    2405 pts/4 S+ 0:00 grep update-notifier
    15421 ? Sl 0:00 update-notifier


    Look up the symbolic link:



    egil@gud:~$ file /proc/15421/exe
    /proc/15421/exe: symbolic link to `/usr/bin/update-notifier'






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 16 '11 at 11:07

























    answered Jun 16 '11 at 10:56









    EgilEgil

    10.7k23446




    10.7k23446













    • Oh yeah, I was almost there. Legend, thank you.

      – SuperJumbo
      Jun 16 '11 at 11:11



















    • Oh yeah, I was almost there. Legend, thank you.

      – SuperJumbo
      Jun 16 '11 at 11:11

















    Oh yeah, I was almost there. Legend, thank you.

    – SuperJumbo
    Jun 16 '11 at 11:11





    Oh yeah, I was almost there. Legend, thank you.

    – SuperJumbo
    Jun 16 '11 at 11:11













    13














    Maybe which is what you are looking for. For instance, on my system



    which firefox 


    returns



    /usr/bin/firefox


    See also Find Path of Application Running on Solaris, Ubuntu, Suse or Redhat Linux .






    share|improve this answer



















    • 6





      which is cool, but it only returns programs in your $PATH. If I run RandomProgramIDownloadedToErisKnowsWhere.bin, this won't be of much use.

      – djeikyb
      Jun 16 '11 at 11:02


















    13














    Maybe which is what you are looking for. For instance, on my system



    which firefox 


    returns



    /usr/bin/firefox


    See also Find Path of Application Running on Solaris, Ubuntu, Suse or Redhat Linux .






    share|improve this answer



















    • 6





      which is cool, but it only returns programs in your $PATH. If I run RandomProgramIDownloadedToErisKnowsWhere.bin, this won't be of much use.

      – djeikyb
      Jun 16 '11 at 11:02
















    13












    13








    13







    Maybe which is what you are looking for. For instance, on my system



    which firefox 


    returns



    /usr/bin/firefox


    See also Find Path of Application Running on Solaris, Ubuntu, Suse or Redhat Linux .






    share|improve this answer













    Maybe which is what you are looking for. For instance, on my system



    which firefox 


    returns



    /usr/bin/firefox


    See also Find Path of Application Running on Solaris, Ubuntu, Suse or Redhat Linux .







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 16 '11 at 10:51









    N.N.N.N.

    8,499154988




    8,499154988








    • 6





      which is cool, but it only returns programs in your $PATH. If I run RandomProgramIDownloadedToErisKnowsWhere.bin, this won't be of much use.

      – djeikyb
      Jun 16 '11 at 11:02
















    • 6





      which is cool, but it only returns programs in your $PATH. If I run RandomProgramIDownloadedToErisKnowsWhere.bin, this won't be of much use.

      – djeikyb
      Jun 16 '11 at 11:02










    6




    6





    which is cool, but it only returns programs in your $PATH. If I run RandomProgramIDownloadedToErisKnowsWhere.bin, this won't be of much use.

    – djeikyb
    Jun 16 '11 at 11:02







    which is cool, but it only returns programs in your $PATH. If I run RandomProgramIDownloadedToErisKnowsWhere.bin, this won't be of much use.

    – djeikyb
    Jun 16 '11 at 11:02













    3














    Providing you've a process ID available, you can use:



    readlink -f /proc/$pid/exe


    (replace $pid by the process ID of a process)



    If the process is not owned by you, you'll have to put sudo in front of it.



    An example for determining the location of the command firefox:





    1. The output of ps ax -o pid,cmd | grep firefox :



      22831 grep --color=auto firefox
      28179 /usr/lib/firefox-4.0.1/firefox-bin



    2. 28179 is the process ID, so you've to run:



      readlink -f /proc/28179/exe


      which outputs:



      /usr/bin/firefox







    share|improve this answer





















    • 2





      You can do cool things with /proc/$pid/exe, if the binary is accidentally deleted, you can restore it with: dd if=/proc/$pid/exe of=restored-binary

      – Lekensteyn
      Jun 16 '11 at 11:05
















    3














    Providing you've a process ID available, you can use:



    readlink -f /proc/$pid/exe


    (replace $pid by the process ID of a process)



    If the process is not owned by you, you'll have to put sudo in front of it.



    An example for determining the location of the command firefox:





    1. The output of ps ax -o pid,cmd | grep firefox :



      22831 grep --color=auto firefox
      28179 /usr/lib/firefox-4.0.1/firefox-bin



    2. 28179 is the process ID, so you've to run:



      readlink -f /proc/28179/exe


      which outputs:



      /usr/bin/firefox







    share|improve this answer





















    • 2





      You can do cool things with /proc/$pid/exe, if the binary is accidentally deleted, you can restore it with: dd if=/proc/$pid/exe of=restored-binary

      – Lekensteyn
      Jun 16 '11 at 11:05














    3












    3








    3







    Providing you've a process ID available, you can use:



    readlink -f /proc/$pid/exe


    (replace $pid by the process ID of a process)



    If the process is not owned by you, you'll have to put sudo in front of it.



    An example for determining the location of the command firefox:





    1. The output of ps ax -o pid,cmd | grep firefox :



      22831 grep --color=auto firefox
      28179 /usr/lib/firefox-4.0.1/firefox-bin



    2. 28179 is the process ID, so you've to run:



      readlink -f /proc/28179/exe


      which outputs:



      /usr/bin/firefox







    share|improve this answer















    Providing you've a process ID available, you can use:



    readlink -f /proc/$pid/exe


    (replace $pid by the process ID of a process)



    If the process is not owned by you, you'll have to put sudo in front of it.



    An example for determining the location of the command firefox:





    1. The output of ps ax -o pid,cmd | grep firefox :



      22831 grep --color=auto firefox
      28179 /usr/lib/firefox-4.0.1/firefox-bin



    2. 28179 is the process ID, so you've to run:



      readlink -f /proc/28179/exe


      which outputs:



      /usr/bin/firefox








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 16 '11 at 11:03

























    answered Jun 16 '11 at 10:57









    LekensteynLekensteyn

    123k49270361




    123k49270361








    • 2





      You can do cool things with /proc/$pid/exe, if the binary is accidentally deleted, you can restore it with: dd if=/proc/$pid/exe of=restored-binary

      – Lekensteyn
      Jun 16 '11 at 11:05














    • 2





      You can do cool things with /proc/$pid/exe, if the binary is accidentally deleted, you can restore it with: dd if=/proc/$pid/exe of=restored-binary

      – Lekensteyn
      Jun 16 '11 at 11:05








    2




    2





    You can do cool things with /proc/$pid/exe, if the binary is accidentally deleted, you can restore it with: dd if=/proc/$pid/exe of=restored-binary

    – Lekensteyn
    Jun 16 '11 at 11:05





    You can do cool things with /proc/$pid/exe, if the binary is accidentally deleted, you can restore it with: dd if=/proc/$pid/exe of=restored-binary

    – Lekensteyn
    Jun 16 '11 at 11:05











    1














    Press Ctrl+Alt+T to go to a terminal and type:



    ls -al /proc/{pid}/fd  


    and then check the output



    This will list all the files your process is associated with...






    share|improve this answer


























    • Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-)

      – Fabby
      Jul 4 '18 at 17:05


















    1














    Press Ctrl+Alt+T to go to a terminal and type:



    ls -al /proc/{pid}/fd  


    and then check the output



    This will list all the files your process is associated with...






    share|improve this answer


























    • Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-)

      – Fabby
      Jul 4 '18 at 17:05
















    1












    1








    1







    Press Ctrl+Alt+T to go to a terminal and type:



    ls -al /proc/{pid}/fd  


    and then check the output



    This will list all the files your process is associated with...






    share|improve this answer















    Press Ctrl+Alt+T to go to a terminal and type:



    ls -al /proc/{pid}/fd  


    and then check the output



    This will list all the files your process is associated with...







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 4 '18 at 17:05









    Fabby

    27k1360161




    27k1360161










    answered Jul 4 '18 at 5:24









    xiaoyifangxiaoyifang

    1572




    1572













    • Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-)

      – Fabby
      Jul 4 '18 at 17:05





















    • Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-)

      – Fabby
      Jul 4 '18 at 17:05



















    Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-)

    – Fabby
    Jul 4 '18 at 17:05







    Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-)

    – Fabby
    Jul 4 '18 at 17:05













    0














    All the commands in the other answers are good, but you could do even more - seeing how some process has been actually run before it got to the process list.



    Run in terminal:



    top


    And while it is running, press keyboard C and you will get a command of the processes that was run.






    share|improve this answer




























      0














      All the commands in the other answers are good, but you could do even more - seeing how some process has been actually run before it got to the process list.



      Run in terminal:



      top


      And while it is running, press keyboard C and you will get a command of the processes that was run.






      share|improve this answer


























        0












        0








        0







        All the commands in the other answers are good, but you could do even more - seeing how some process has been actually run before it got to the process list.



        Run in terminal:



        top


        And while it is running, press keyboard C and you will get a command of the processes that was run.






        share|improve this answer













        All the commands in the other answers are good, but you could do even more - seeing how some process has been actually run before it got to the process list.



        Run in terminal:



        top


        And while it is running, press keyboard C and you will get a command of the processes that was run.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 14 at 16:04









        AleksAleks

        197112




        197112






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f49024%2fhow-do-i-determine-the-path-to-a-binary-of-a-process%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

            Eduardo VII do Reino Unido