Skip to content

Get the path of the running process #83

@ganeshkbhat

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
        }
    });
});

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