Skip to content

Get the path of the running process #83

Description

@ganeshkbhat

I have two nginx executables running.

  1. C:/nginx/nginx.exe (or say usr/bin)
  2. C:/second/nginx/nginx.exe (or say $home/local/nginx)

I wish to get the executable's path of the running nginx file whether it is the first or second. I am aware of this command wmic process where "ExecutablePath like 'c:\\nginx\\nginx%'" get ProcessID in windows. Is there a way I can do it using ps-node so it applies to both linux and win?

var ps = require('ps-node');
ps.lookup({
    command: 'nginx',
    psargs: 'ux'
    }, function(err, resultList ) {
    if (err) {
        throw new Error( err );
    }
    resultList.forEach(function( process ){
        if( process ){
            console.log(process.pid, process.command, **process.ExecutablePath**, process.arguments );
            // **process.ExecutablePath** => c:/nginx or usr/bin
        }
    });
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions