node.js how to check a process is running by the process name?

user3552178

i run node.js in linux, from node.js how to check if a process is running from the process name ? Worst case i use child_process, but wonder if better ways ?

Thanks !

Samuel Toh

You can use the ps-node package.

https://www.npmjs.com/package/ps-node

var ps = require('ps-node');

// A simple pid lookup 
ps.lookup({
    command: 'node',
    psargs: 'ux'
    }, function(err, resultList ) {
    if (err) {
        throw new Error( err );
    }

    resultList.forEach(function( process ){
        if( process ){
            console.log( 'PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments );
        }
    });
});

I believe you'll be looking at this example. Check out the site, they have plenty of other usages. Give it a try.

Just incase you are not bound to nodejs, from linux command line you can also do ps -ef | grep "YOUR_PROCESS_NAME_e.g._nodejs" to check for a running process.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to check if a process is running on Windows?

From Dev

How to check the process is already running or not

From Dev

How to check the process is already running or not

From Dev

How to check a mac process exists by process name

From Dev

node js process name on windows

From Dev

setInterval() keeps Node.js process running

From Dev

How do I check if a running process is a background process?

From Dev

How do I check if a running process is a background process?

From Dev

Lua: how to check whether a process is running

From Java

How to check if a process is running inside docker container

From Dev

How can I check if a process is running in Linux?

From Dev

How to check in Mac OSX with Python if a process is RUNNING or not

From Dev

How to Correctly Check if a Process is running and Stop it

From Dev

How to check is there a process running with the given handle

From Dev

How to check is a certain process is running - java on linux

From Dev

How to check in Mac OSX with Python if a process is RUNNING or not

From Dev

How to check is a certain process is running - java on linux

From Dev

Check if a process is running or not?

From Dev

Check if a process is running on Bosun

From Dev

Check if process is running and kill it

From Dev

Check if process is running - Windows

From Dev

How to detect if a Node spawned process is still running?

From Dev

Running an electron process as plain node process?

From Dev

Check if remote process is running (linux)

From Dev

Shell script to check if process is running

From Dev

Check if a process is running on a remote machine

From Dev

Check if a process is running with shell script

From Dev

Check if remote process is running (linux)

From Dev

Name of running threads inside a process

Related Related

  1. 1

    How to check if a process is running on Windows?

  2. 2

    How to check the process is already running or not

  3. 3

    How to check the process is already running or not

  4. 4

    How to check a mac process exists by process name

  5. 5

    node js process name on windows

  6. 6

    setInterval() keeps Node.js process running

  7. 7

    How do I check if a running process is a background process?

  8. 8

    How do I check if a running process is a background process?

  9. 9

    Lua: how to check whether a process is running

  10. 10

    How to check if a process is running inside docker container

  11. 11

    How can I check if a process is running in Linux?

  12. 12

    How to check in Mac OSX with Python if a process is RUNNING or not

  13. 13

    How to Correctly Check if a Process is running and Stop it

  14. 14

    How to check is there a process running with the given handle

  15. 15

    How to check is a certain process is running - java on linux

  16. 16

    How to check in Mac OSX with Python if a process is RUNNING or not

  17. 17

    How to check is a certain process is running - java on linux

  18. 18

    Check if a process is running or not?

  19. 19

    Check if a process is running on Bosun

  20. 20

    Check if process is running and kill it

  21. 21

    Check if process is running - Windows

  22. 22

    How to detect if a Node spawned process is still running?

  23. 23

    Running an electron process as plain node process?

  24. 24

    Check if remote process is running (linux)

  25. 25

    Shell script to check if process is running

  26. 26

    Check if a process is running on a remote machine

  27. 27

    Check if a process is running with shell script

  28. 28

    Check if remote process is running (linux)

  29. 29

    Name of running threads inside a process

HotTag

Archive