To see PM2 in action, we're going to kill our Node.js process manually, and see if PM2 will automatically restart it. We'll use the npx pm2 list command, which lists all processes in a static table:
hobnob@hobnob:$ npx pm2 list
┌───────┬────┬───────┬────────┬───┬────────┬─────┬─────────┐
│ Name │ id │ pid │ status │ ↺ │ uptime │ cpu │ mem │
├───────┼────┼───────┼────────┼───┼────────┼─────┼─────────┤
│ index │ 0 │ 15540 │ online │ 0 │ 20m │ 0% │ 40.8 MB │
└───────┴────┴───────┴────────┴───┴────────┴─────┴─────────┘
hobnob@hobnob:$ kill 15540
hobnob@hobnob:$ npx pm2 list
┌───────┬────┬───────┬────────┬───┬────────┬─────┬─────────┐
│ Name │ id │ pid │ status │ ↺ │ uptime │ cpu │ mem │
├───────┼────┼───────┼────────┼───┼────────┼─────┼─────────┤
│ index │ 0 │ 16323 │ online │ 1 │ 2s │ 0% │ 47.9 MB │
└───────┴────┴───────┴────────┴───┴────────┴─────┴─────────┘
As you can see, pm2 started a new process, with a different process ID (PID), once the old process died. The restart count has also increased to 1.