How do I get the path of a process in Unix / Linux

how to find path of running process in linux
linux find where a process is running from
kill process linux
how to know which process is using a directory in linux
get pwd of process linux
get process path from pid windows
how to get process id in unix shell script
search processes by name linux

In Windows environment there is an API to obtain the path which is running a process. Is there something similar in Unix / Linux?

Or is there some other way to do that in these environments?


On Linux, the symlink /proc/<pid>/exe has the path of the executable. Use the command readlink -f /proc/<pid>/exe to get the value.

On AIX, this file does not exist. You could compare cksum <actual path to binary> and cksum /proc/<pid>/object/a.out.

How can I know the absolute path of a running process?, This gives you the current working directory of the pid, not its absolute path. See the Unix FAQ for a little more detail, particularly questions 4.3 and 4.4. Whenever you issue a command in Unix, it creates, or starts, a new process. When you tried out the ls command to list the directory contents, you started a process. A process, in simple terms, is an instance of a running program.


How to find out from which folder a process is running?, Duplicate of https://unix.stackexchange.com/questions/94357/find-out-current-​working-directory-of-a-running-process ? There are 3 methods that I'm aware of:. You need to use the ps command. It provides information about the currently running processes, including their process identification numbers (PIDs). Both Linux and UNIX support the ps command to display information about all running process. The ps command gives a snapshot of the current processes.


A little bit late, but all the answers were specific to linux.

If you need also unix, then you need this:

char * getExecPath (char * path,size_t dest_len, char * argv0)
{
    char * baseName = NULL;
    char * systemPath = NULL;
    char * candidateDir = NULL;

    /* the easiest case: we are in linux */
    size_t buff_len;
    if (buff_len = readlink ("/proc/self/exe", path, dest_len - 1) != -1)
    {
        path [buff_len] = '\0';
        dirname (path);
        strcat  (path, "/");
        return path;
    }

    /* Ups... not in linux, no  guarantee */

    /* check if we have something like execve("foobar", NULL, NULL) */
    if (argv0 == NULL)
    {
        /* we surrender and give current path instead */
        if (getcwd (path, dest_len) == NULL) return NULL;
        strcat  (path, "/");
        return path;
    }


    /* argv[0] */
    /* if dest_len < PATH_MAX may cause buffer overflow */
    if ((realpath (argv0, path)) && (!access (path, F_OK)))
    {
        dirname (path);
        strcat  (path, "/");
        return path;
    }

    /* Current path */
    baseName = basename (argv0);
    if (getcwd (path, dest_len - strlen (baseName) - 1) == NULL)
        return NULL;

    strcat (path, "/");
    strcat (path, baseName);
    if (access (path, F_OK) == 0)
    {
        dirname (path);
        strcat  (path, "/");
        return path;
    }

    /* Try the PATH. */
    systemPath = getenv ("PATH");
    if (systemPath != NULL)
    {
        dest_len--;
        systemPath = strdup (systemPath);
        for (candidateDir = strtok (systemPath, ":"); candidateDir != NULL; candidateDir = strtok (NULL, ":"))
        {
            strncpy (path, candidateDir, dest_len);
            strncat (path, "/", dest_len);
            strncat (path, baseName, dest_len);

            if (access(path, F_OK) == 0)
            {
                free (systemPath);
                dirname (path);
                strcat  (path, "/");
                return path;
            }
        }
        free(systemPath);
        dest_len++;
    }

    /* again someone has use execve: we dont knowe the executable name; we surrender and give instead current path */
    if (getcwd (path, dest_len - 1) == NULL) return NULL;
    strcat  (path, "/");
    return path;
}

EDITED: Fixed the bug reported by Mark lakata.

Is it possible to find the path of a running program?, The process running now works, so I want to delete (or rename) the other one. ps ax|grep "xmms" returns 8505 ? SLl 2:38 xmms2d -v without path  In Linux or Unix-like file systems, the human-readable address of a resource is defined by PATH. On Unix / Linux like operating systems, (as well as on DOS / Windows and its descendants), PATH is an environment variable listing a set of paths to directories where executable may be found.


I use:

ps -ef | grep 786

Replace 786 with your PID or process name.

process executable file full path, hi guys i give "ps -ef | grep some_executable_file" on the command line. this "​some_executable_file" resides on many paths which r included in the PATH  If you are using tcsh or csh, shell enter: ## please note 'path' is case sensitivity and must be in lowercase ## set path = ($path / path / to / dir1) set path = ($path / path / to / dir1 / path / to / dir2)


pwdx <process id>

This command will fetch the process path from where it is executing.

How can I know the absolute path of a running process? on solaris , You can use pwdx in solaris and linux. pwdx <pid_number>. example: pwdx $$ 25711: /export/home/pippo. On Linux, the symlink /proc/<pid>/exe has the path of the executable. Use the command readlink -f /proc/<pid>/exe to get the value. On AIX, this file does not exist. You could compare cksum <actual path to binary> and cksum /proc/<pid>/object/a.out.


Find the correct path to an executable file in Unix, Several Unix dialects use the whereis command to find where programs, The first path is the location of the lpr executable, and the second path is the Linux or Unix systems support, see Get help for Linux or Unix at IU. When I wind up with a stubborn process, I tend to start off with the killall command as it is the most efficient route to termination. However, when you wind up with a really feisty process, the kill command is the way to go. Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.


Linux / UNIX: Find out or determine if process pid is running, Linux / UNIX: Find out or determine if process pid is running How do I find out my process is running on a Unix-like operating systems? but since the path of process AddUser is too long..the output of pgrep does not shows  Hi Frindz, I want to get the entire path of a file. I am in root directory and i know the file name, However dont know the path where it is. Please tell me the command to get the entire path for the f | The UNIX and Linux Forums


Unix / Linux - Processes Management, When you tried out the ls command to list the directory contents, you started a process. A process, in simple terms, is an instance of a running program. The