Sunday, April 16, 2017

How to find out from which folder a process is running on linux ?

First step find out the pid of the particular process.
Example:

deb@linuxforfreshers.com:~$ pidof chrome

15499

Or

deb@linuxforfreshers.com:~$ ps -ef | grep chrome
deb     15499 15410  0 07:46 ?        00:02:33 /opt/google/chrome/chrome

Note: In above line second filed is pid number.

Method 1:
Using pwdx command.
Syntax:
pwdx  pid_number

Example:

deb@linuxforfreshers.com:~$ pwdx 15499
15499: /home/deb

Method 2:

Using lsof command.
Syntax: lsof -p PID | grep cwd

Example:

deb@linuxforfreshers.com:~$ lsof -p 15499| grep cwd
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /home/deb/.gvfs
      Output information may be incomplete.
chrome  15499 deb  cwd    DIR                8,6      4096  5767170 /home/deb

Method 3:

Using readlink command
Syntax: readlink -e /proc/PID/cwd

Example:

deb@linuxforfreshers.com:~$ readlink -e /proc/15499/cwd
/home/deb

Method 4:

Using ls command
Syntax: ls -l /proc/<PID>/cwd

Example:
deb@linuxforfreshers.com:~$ ls -l /proc/15499/cwd
lrwxrwxrwx 1 deb deb 0 Apr 13 16:21 /proc/15499/cwd -> /home/deb

Method 5:

Using ps command
Syntax : ps auxwwwe | grep process_name


It will give all the list of process running from current directory.

No comments:

Post a Comment