Find out current working directory of a running process?












139















What command(s) can one use to find out the current working directory (CWD) of a running process? These would be commands you could use externally from the process.










share|improve this question





























    139















    What command(s) can one use to find out the current working directory (CWD) of a running process? These would be commands you could use externally from the process.










    share|improve this question



























      139












      139








      139


      50






      What command(s) can one use to find out the current working directory (CWD) of a running process? These would be commands you could use externally from the process.










      share|improve this question
















      What command(s) can one use to find out the current working directory (CWD) of a running process? These would be commands you could use externally from the process.







      shell command-line process cwd






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 10 '13 at 0:52









      Gilles

      532k12810651592




      532k12810651592










      asked Oct 10 '13 at 0:15









      slmslm

      248k66517678




      248k66517678






















          4 Answers
          4






          active

          oldest

          votes


















          177














          There are 3 methods that I'm aware of:



          pwdx



          $ pwdx <PID>


          lsof



          $ lsof -p <PID> | grep cwd


          /proc



          $ readlink -e /proc/<PID>/cwd


          Examples



          Say we have this process.



          $ pgrep nautilus
          12136


          Then if we use pwdx:



          $ pwdx 12136
          12136: /home/saml


          Or you can use lsof:



          $ lsof -p 12136 | grep cwd
          nautilus 12136 saml cwd DIR 253,2 32768 10354689 /home/saml


          Or you can poke directly into the /proc:



          $ readlink -e /proc/12136/cwd/
          /home/saml





          share|improve this answer



















          • 2





            I would say /proc is canonical, with lsof being useful, but pwdx is cool.

            – ChuckCottrill
            Oct 10 '13 at 0:33








          • 3





            Not all Unices have /proc.

            – reinierpost
            Oct 10 '13 at 9:30











          • A similar but different question: unix.stackexchange.com/questions/173868/…

            – Sibbs Gambling
            Dec 12 '14 at 5:03








          • 1





            pwdx works for me.

            – aroth
            Feb 8 '16 at 7:11











          • Here is a simple way (from slm's answer) pwdx pgrep <process-name>

            – Madhusoodan P
            May 8 '18 at 14:18



















          25














          I assume that you have the process ID in pid. Most methods on most systems will require that the shell you're doing this from is running as the same user as the target process (or root).



          On Linux and Solaris and perhaps some other System V unices:



          cd /proc/$pid/cwd && pwd


          On Linux (except embedded systems where readlink is not available) but not Solaris:



          readlink /proc/$pid/cwd


          On just about any unix variant, you can use lsof. Beware that if there is a newline, it will be printed as n (indistinguishable from backslash followed by n). If you feel lucky, you can use the second form, which silently chokes on all whitespace in the directory name.



          lsof -a -Fn -p $pid -d cwd | sed -e '1d' -e '2s/^n/'
          lsof -p $pid | awk '$4=="cwd" {print $9}'




          Bonus: if you need to cause a process to change its current directory, you can do it with a debugger. This is useful for example to move a long-running program that doesn't care about its current directory out of a directory that you want to remove. Not all programs appreciate having their current directory changed under their feet — for example a shell is likely to crash.



          #!/bin/sh

          # Use gdb to change the working directory of a process from outside.
          # This could be generalized to a lot of other things.

          if [ $# -ne 2 ]; then
          echo 1>&2 "Usage: $0 PID DIR"
          exit 120
          fi
          case "$1" in
          *[!0-9]*) echo 1>&2 "Invalid pid `$1'"; exit 3;;
          esac
          case "$2" in
          *[\"]*)
          echo 1>&2 "Unsupported character in directory name, sorry."
          exit 3;;
          esac

          gdb -n -pid "$1" -batch -x /dev/stdin <<EOF
          call chdir("$2")
          detach
          quit
          EOF





          share|improve this answer


























          • Nice touch adding the details in about moving. Good little nugget to add to the site!

            – slm
            Oct 10 '13 at 0:56











          • Can you comment at all on the ubiquity of pwdx on other Unixes?

            – slm
            Oct 10 '13 at 1:00











          • On OpenBSD, at least, lsof only reports the mount point of the process's CWD.

            – kurtm
            Oct 10 '13 at 1:11











          • @slm pwdx is present on Solaris since the 20th century, Linux since the mid-2000s (imitating Solaris, says the man page). Not present on any other unix AFAIK.

            – Gilles
            Oct 10 '13 at 1:12













          • @kurtm - any better method on BSD? Also is pwdx there?

            – slm
            Oct 10 '13 at 1:17





















          8














          If your system has /proc, you can always do:



          readlink -e /proc/$$/cwd


          If you want to find out the CWD from a different process than the one you're interested in, you obviously need to replace $$ with the PID of your process of interest.






          share|improve this answer































            0














            Based @Gilles answer..



            if you know PID of your process.. for Mac OSX and Linux use:



            lsof -p PID | awk '$4=="cwd" {print $9}'


            to get working dir of process..






            share|improve this answer








            New contributor




            Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              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: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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%2funix.stackexchange.com%2fquestions%2f94357%2ffind-out-current-working-directory-of-a-running-process%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              177














              There are 3 methods that I'm aware of:



              pwdx



              $ pwdx <PID>


              lsof



              $ lsof -p <PID> | grep cwd


              /proc



              $ readlink -e /proc/<PID>/cwd


              Examples



              Say we have this process.



              $ pgrep nautilus
              12136


              Then if we use pwdx:



              $ pwdx 12136
              12136: /home/saml


              Or you can use lsof:



              $ lsof -p 12136 | grep cwd
              nautilus 12136 saml cwd DIR 253,2 32768 10354689 /home/saml


              Or you can poke directly into the /proc:



              $ readlink -e /proc/12136/cwd/
              /home/saml





              share|improve this answer



















              • 2





                I would say /proc is canonical, with lsof being useful, but pwdx is cool.

                – ChuckCottrill
                Oct 10 '13 at 0:33








              • 3





                Not all Unices have /proc.

                – reinierpost
                Oct 10 '13 at 9:30











              • A similar but different question: unix.stackexchange.com/questions/173868/…

                – Sibbs Gambling
                Dec 12 '14 at 5:03








              • 1





                pwdx works for me.

                – aroth
                Feb 8 '16 at 7:11











              • Here is a simple way (from slm's answer) pwdx pgrep <process-name>

                – Madhusoodan P
                May 8 '18 at 14:18
















              177














              There are 3 methods that I'm aware of:



              pwdx



              $ pwdx <PID>


              lsof



              $ lsof -p <PID> | grep cwd


              /proc



              $ readlink -e /proc/<PID>/cwd


              Examples



              Say we have this process.



              $ pgrep nautilus
              12136


              Then if we use pwdx:



              $ pwdx 12136
              12136: /home/saml


              Or you can use lsof:



              $ lsof -p 12136 | grep cwd
              nautilus 12136 saml cwd DIR 253,2 32768 10354689 /home/saml


              Or you can poke directly into the /proc:



              $ readlink -e /proc/12136/cwd/
              /home/saml





              share|improve this answer



















              • 2





                I would say /proc is canonical, with lsof being useful, but pwdx is cool.

                – ChuckCottrill
                Oct 10 '13 at 0:33








              • 3





                Not all Unices have /proc.

                – reinierpost
                Oct 10 '13 at 9:30











              • A similar but different question: unix.stackexchange.com/questions/173868/…

                – Sibbs Gambling
                Dec 12 '14 at 5:03








              • 1





                pwdx works for me.

                – aroth
                Feb 8 '16 at 7:11











              • Here is a simple way (from slm's answer) pwdx pgrep <process-name>

                – Madhusoodan P
                May 8 '18 at 14:18














              177












              177








              177







              There are 3 methods that I'm aware of:



              pwdx



              $ pwdx <PID>


              lsof



              $ lsof -p <PID> | grep cwd


              /proc



              $ readlink -e /proc/<PID>/cwd


              Examples



              Say we have this process.



              $ pgrep nautilus
              12136


              Then if we use pwdx:



              $ pwdx 12136
              12136: /home/saml


              Or you can use lsof:



              $ lsof -p 12136 | grep cwd
              nautilus 12136 saml cwd DIR 253,2 32768 10354689 /home/saml


              Or you can poke directly into the /proc:



              $ readlink -e /proc/12136/cwd/
              /home/saml





              share|improve this answer













              There are 3 methods that I'm aware of:



              pwdx



              $ pwdx <PID>


              lsof



              $ lsof -p <PID> | grep cwd


              /proc



              $ readlink -e /proc/<PID>/cwd


              Examples



              Say we have this process.



              $ pgrep nautilus
              12136


              Then if we use pwdx:



              $ pwdx 12136
              12136: /home/saml


              Or you can use lsof:



              $ lsof -p 12136 | grep cwd
              nautilus 12136 saml cwd DIR 253,2 32768 10354689 /home/saml


              Or you can poke directly into the /proc:



              $ readlink -e /proc/12136/cwd/
              /home/saml






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Oct 10 '13 at 0:19









              slmslm

              248k66517678




              248k66517678








              • 2





                I would say /proc is canonical, with lsof being useful, but pwdx is cool.

                – ChuckCottrill
                Oct 10 '13 at 0:33








              • 3





                Not all Unices have /proc.

                – reinierpost
                Oct 10 '13 at 9:30











              • A similar but different question: unix.stackexchange.com/questions/173868/…

                – Sibbs Gambling
                Dec 12 '14 at 5:03








              • 1





                pwdx works for me.

                – aroth
                Feb 8 '16 at 7:11











              • Here is a simple way (from slm's answer) pwdx pgrep <process-name>

                – Madhusoodan P
                May 8 '18 at 14:18














              • 2





                I would say /proc is canonical, with lsof being useful, but pwdx is cool.

                – ChuckCottrill
                Oct 10 '13 at 0:33








              • 3





                Not all Unices have /proc.

                – reinierpost
                Oct 10 '13 at 9:30











              • A similar but different question: unix.stackexchange.com/questions/173868/…

                – Sibbs Gambling
                Dec 12 '14 at 5:03








              • 1





                pwdx works for me.

                – aroth
                Feb 8 '16 at 7:11











              • Here is a simple way (from slm's answer) pwdx pgrep <process-name>

                – Madhusoodan P
                May 8 '18 at 14:18








              2




              2





              I would say /proc is canonical, with lsof being useful, but pwdx is cool.

              – ChuckCottrill
              Oct 10 '13 at 0:33







              I would say /proc is canonical, with lsof being useful, but pwdx is cool.

              – ChuckCottrill
              Oct 10 '13 at 0:33






              3




              3





              Not all Unices have /proc.

              – reinierpost
              Oct 10 '13 at 9:30





              Not all Unices have /proc.

              – reinierpost
              Oct 10 '13 at 9:30













              A similar but different question: unix.stackexchange.com/questions/173868/…

              – Sibbs Gambling
              Dec 12 '14 at 5:03







              A similar but different question: unix.stackexchange.com/questions/173868/…

              – Sibbs Gambling
              Dec 12 '14 at 5:03






              1




              1





              pwdx works for me.

              – aroth
              Feb 8 '16 at 7:11





              pwdx works for me.

              – aroth
              Feb 8 '16 at 7:11













              Here is a simple way (from slm's answer) pwdx pgrep <process-name>

              – Madhusoodan P
              May 8 '18 at 14:18





              Here is a simple way (from slm's answer) pwdx pgrep <process-name>

              – Madhusoodan P
              May 8 '18 at 14:18













              25














              I assume that you have the process ID in pid. Most methods on most systems will require that the shell you're doing this from is running as the same user as the target process (or root).



              On Linux and Solaris and perhaps some other System V unices:



              cd /proc/$pid/cwd && pwd


              On Linux (except embedded systems where readlink is not available) but not Solaris:



              readlink /proc/$pid/cwd


              On just about any unix variant, you can use lsof. Beware that if there is a newline, it will be printed as n (indistinguishable from backslash followed by n). If you feel lucky, you can use the second form, which silently chokes on all whitespace in the directory name.



              lsof -a -Fn -p $pid -d cwd | sed -e '1d' -e '2s/^n/'
              lsof -p $pid | awk '$4=="cwd" {print $9}'




              Bonus: if you need to cause a process to change its current directory, you can do it with a debugger. This is useful for example to move a long-running program that doesn't care about its current directory out of a directory that you want to remove. Not all programs appreciate having their current directory changed under their feet — for example a shell is likely to crash.



              #!/bin/sh

              # Use gdb to change the working directory of a process from outside.
              # This could be generalized to a lot of other things.

              if [ $# -ne 2 ]; then
              echo 1>&2 "Usage: $0 PID DIR"
              exit 120
              fi
              case "$1" in
              *[!0-9]*) echo 1>&2 "Invalid pid `$1'"; exit 3;;
              esac
              case "$2" in
              *[\"]*)
              echo 1>&2 "Unsupported character in directory name, sorry."
              exit 3;;
              esac

              gdb -n -pid "$1" -batch -x /dev/stdin <<EOF
              call chdir("$2")
              detach
              quit
              EOF





              share|improve this answer


























              • Nice touch adding the details in about moving. Good little nugget to add to the site!

                – slm
                Oct 10 '13 at 0:56











              • Can you comment at all on the ubiquity of pwdx on other Unixes?

                – slm
                Oct 10 '13 at 1:00











              • On OpenBSD, at least, lsof only reports the mount point of the process's CWD.

                – kurtm
                Oct 10 '13 at 1:11











              • @slm pwdx is present on Solaris since the 20th century, Linux since the mid-2000s (imitating Solaris, says the man page). Not present on any other unix AFAIK.

                – Gilles
                Oct 10 '13 at 1:12













              • @kurtm - any better method on BSD? Also is pwdx there?

                – slm
                Oct 10 '13 at 1:17


















              25














              I assume that you have the process ID in pid. Most methods on most systems will require that the shell you're doing this from is running as the same user as the target process (or root).



              On Linux and Solaris and perhaps some other System V unices:



              cd /proc/$pid/cwd && pwd


              On Linux (except embedded systems where readlink is not available) but not Solaris:



              readlink /proc/$pid/cwd


              On just about any unix variant, you can use lsof. Beware that if there is a newline, it will be printed as n (indistinguishable from backslash followed by n). If you feel lucky, you can use the second form, which silently chokes on all whitespace in the directory name.



              lsof -a -Fn -p $pid -d cwd | sed -e '1d' -e '2s/^n/'
              lsof -p $pid | awk '$4=="cwd" {print $9}'




              Bonus: if you need to cause a process to change its current directory, you can do it with a debugger. This is useful for example to move a long-running program that doesn't care about its current directory out of a directory that you want to remove. Not all programs appreciate having their current directory changed under their feet — for example a shell is likely to crash.



              #!/bin/sh

              # Use gdb to change the working directory of a process from outside.
              # This could be generalized to a lot of other things.

              if [ $# -ne 2 ]; then
              echo 1>&2 "Usage: $0 PID DIR"
              exit 120
              fi
              case "$1" in
              *[!0-9]*) echo 1>&2 "Invalid pid `$1'"; exit 3;;
              esac
              case "$2" in
              *[\"]*)
              echo 1>&2 "Unsupported character in directory name, sorry."
              exit 3;;
              esac

              gdb -n -pid "$1" -batch -x /dev/stdin <<EOF
              call chdir("$2")
              detach
              quit
              EOF





              share|improve this answer


























              • Nice touch adding the details in about moving. Good little nugget to add to the site!

                – slm
                Oct 10 '13 at 0:56











              • Can you comment at all on the ubiquity of pwdx on other Unixes?

                – slm
                Oct 10 '13 at 1:00











              • On OpenBSD, at least, lsof only reports the mount point of the process's CWD.

                – kurtm
                Oct 10 '13 at 1:11











              • @slm pwdx is present on Solaris since the 20th century, Linux since the mid-2000s (imitating Solaris, says the man page). Not present on any other unix AFAIK.

                – Gilles
                Oct 10 '13 at 1:12













              • @kurtm - any better method on BSD? Also is pwdx there?

                – slm
                Oct 10 '13 at 1:17
















              25












              25








              25







              I assume that you have the process ID in pid. Most methods on most systems will require that the shell you're doing this from is running as the same user as the target process (or root).



              On Linux and Solaris and perhaps some other System V unices:



              cd /proc/$pid/cwd && pwd


              On Linux (except embedded systems where readlink is not available) but not Solaris:



              readlink /proc/$pid/cwd


              On just about any unix variant, you can use lsof. Beware that if there is a newline, it will be printed as n (indistinguishable from backslash followed by n). If you feel lucky, you can use the second form, which silently chokes on all whitespace in the directory name.



              lsof -a -Fn -p $pid -d cwd | sed -e '1d' -e '2s/^n/'
              lsof -p $pid | awk '$4=="cwd" {print $9}'




              Bonus: if you need to cause a process to change its current directory, you can do it with a debugger. This is useful for example to move a long-running program that doesn't care about its current directory out of a directory that you want to remove. Not all programs appreciate having their current directory changed under their feet — for example a shell is likely to crash.



              #!/bin/sh

              # Use gdb to change the working directory of a process from outside.
              # This could be generalized to a lot of other things.

              if [ $# -ne 2 ]; then
              echo 1>&2 "Usage: $0 PID DIR"
              exit 120
              fi
              case "$1" in
              *[!0-9]*) echo 1>&2 "Invalid pid `$1'"; exit 3;;
              esac
              case "$2" in
              *[\"]*)
              echo 1>&2 "Unsupported character in directory name, sorry."
              exit 3;;
              esac

              gdb -n -pid "$1" -batch -x /dev/stdin <<EOF
              call chdir("$2")
              detach
              quit
              EOF





              share|improve this answer















              I assume that you have the process ID in pid. Most methods on most systems will require that the shell you're doing this from is running as the same user as the target process (or root).



              On Linux and Solaris and perhaps some other System V unices:



              cd /proc/$pid/cwd && pwd


              On Linux (except embedded systems where readlink is not available) but not Solaris:



              readlink /proc/$pid/cwd


              On just about any unix variant, you can use lsof. Beware that if there is a newline, it will be printed as n (indistinguishable from backslash followed by n). If you feel lucky, you can use the second form, which silently chokes on all whitespace in the directory name.



              lsof -a -Fn -p $pid -d cwd | sed -e '1d' -e '2s/^n/'
              lsof -p $pid | awk '$4=="cwd" {print $9}'




              Bonus: if you need to cause a process to change its current directory, you can do it with a debugger. This is useful for example to move a long-running program that doesn't care about its current directory out of a directory that you want to remove. Not all programs appreciate having their current directory changed under their feet — for example a shell is likely to crash.



              #!/bin/sh

              # Use gdb to change the working directory of a process from outside.
              # This could be generalized to a lot of other things.

              if [ $# -ne 2 ]; then
              echo 1>&2 "Usage: $0 PID DIR"
              exit 120
              fi
              case "$1" in
              *[!0-9]*) echo 1>&2 "Invalid pid `$1'"; exit 3;;
              esac
              case "$2" in
              *[\"]*)
              echo 1>&2 "Unsupported character in directory name, sorry."
              exit 3;;
              esac

              gdb -n -pid "$1" -batch -x /dev/stdin <<EOF
              call chdir("$2")
              detach
              quit
              EOF






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Oct 20 '13 at 1:30

























              answered Oct 10 '13 at 0:52









              GillesGilles

              532k12810651592




              532k12810651592













              • Nice touch adding the details in about moving. Good little nugget to add to the site!

                – slm
                Oct 10 '13 at 0:56











              • Can you comment at all on the ubiquity of pwdx on other Unixes?

                – slm
                Oct 10 '13 at 1:00











              • On OpenBSD, at least, lsof only reports the mount point of the process's CWD.

                – kurtm
                Oct 10 '13 at 1:11











              • @slm pwdx is present on Solaris since the 20th century, Linux since the mid-2000s (imitating Solaris, says the man page). Not present on any other unix AFAIK.

                – Gilles
                Oct 10 '13 at 1:12













              • @kurtm - any better method on BSD? Also is pwdx there?

                – slm
                Oct 10 '13 at 1:17





















              • Nice touch adding the details in about moving. Good little nugget to add to the site!

                – slm
                Oct 10 '13 at 0:56











              • Can you comment at all on the ubiquity of pwdx on other Unixes?

                – slm
                Oct 10 '13 at 1:00











              • On OpenBSD, at least, lsof only reports the mount point of the process's CWD.

                – kurtm
                Oct 10 '13 at 1:11











              • @slm pwdx is present on Solaris since the 20th century, Linux since the mid-2000s (imitating Solaris, says the man page). Not present on any other unix AFAIK.

                – Gilles
                Oct 10 '13 at 1:12













              • @kurtm - any better method on BSD? Also is pwdx there?

                – slm
                Oct 10 '13 at 1:17



















              Nice touch adding the details in about moving. Good little nugget to add to the site!

              – slm
              Oct 10 '13 at 0:56





              Nice touch adding the details in about moving. Good little nugget to add to the site!

              – slm
              Oct 10 '13 at 0:56













              Can you comment at all on the ubiquity of pwdx on other Unixes?

              – slm
              Oct 10 '13 at 1:00





              Can you comment at all on the ubiquity of pwdx on other Unixes?

              – slm
              Oct 10 '13 at 1:00













              On OpenBSD, at least, lsof only reports the mount point of the process's CWD.

              – kurtm
              Oct 10 '13 at 1:11





              On OpenBSD, at least, lsof only reports the mount point of the process's CWD.

              – kurtm
              Oct 10 '13 at 1:11













              @slm pwdx is present on Solaris since the 20th century, Linux since the mid-2000s (imitating Solaris, says the man page). Not present on any other unix AFAIK.

              – Gilles
              Oct 10 '13 at 1:12







              @slm pwdx is present on Solaris since the 20th century, Linux since the mid-2000s (imitating Solaris, says the man page). Not present on any other unix AFAIK.

              – Gilles
              Oct 10 '13 at 1:12















              @kurtm - any better method on BSD? Also is pwdx there?

              – slm
              Oct 10 '13 at 1:17







              @kurtm - any better method on BSD? Also is pwdx there?

              – slm
              Oct 10 '13 at 1:17













              8














              If your system has /proc, you can always do:



              readlink -e /proc/$$/cwd


              If you want to find out the CWD from a different process than the one you're interested in, you obviously need to replace $$ with the PID of your process of interest.






              share|improve this answer




























                8














                If your system has /proc, you can always do:



                readlink -e /proc/$$/cwd


                If you want to find out the CWD from a different process than the one you're interested in, you obviously need to replace $$ with the PID of your process of interest.






                share|improve this answer


























                  8












                  8








                  8







                  If your system has /proc, you can always do:



                  readlink -e /proc/$$/cwd


                  If you want to find out the CWD from a different process than the one you're interested in, you obviously need to replace $$ with the PID of your process of interest.






                  share|improve this answer













                  If your system has /proc, you can always do:



                  readlink -e /proc/$$/cwd


                  If you want to find out the CWD from a different process than the one you're interested in, you obviously need to replace $$ with the PID of your process of interest.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 10 '13 at 0:18









                  Joseph R.Joseph R.

                  28.1k374114




                  28.1k374114























                      0














                      Based @Gilles answer..



                      if you know PID of your process.. for Mac OSX and Linux use:



                      lsof -p PID | awk '$4=="cwd" {print $9}'


                      to get working dir of process..






                      share|improve this answer








                      New contributor




                      Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        Based @Gilles answer..



                        if you know PID of your process.. for Mac OSX and Linux use:



                        lsof -p PID | awk '$4=="cwd" {print $9}'


                        to get working dir of process..






                        share|improve this answer








                        New contributor




                        Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          Based @Gilles answer..



                          if you know PID of your process.. for Mac OSX and Linux use:



                          lsof -p PID | awk '$4=="cwd" {print $9}'


                          to get working dir of process..






                          share|improve this answer








                          New contributor




                          Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          Based @Gilles answer..



                          if you know PID of your process.. for Mac OSX and Linux use:



                          lsof -p PID | awk '$4=="cwd" {print $9}'


                          to get working dir of process..







                          share|improve this answer








                          New contributor




                          Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer






                          New contributor




                          Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 14 hours ago









                          Dariusz FilipiakDariusz Filipiak

                          1012




                          1012




                          New contributor




                          Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          Dariusz Filipiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • 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%2funix.stackexchange.com%2fquestions%2f94357%2ffind-out-current-working-directory-of-a-running-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

                              Loup dans la culture

                              How to solve the problem of ntp “Unable to contact time server” from KDE?

                              ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux