Killing a process

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 15540hobnob@hobnob:$ npx pm2 list┌───────┬────┬───────┬────────┬───┬────────┬─────┬─────────┐│ Name  │ id │ pid   │ status │ ↺ │ uptime │ cpu │ mem     │├───────┼────┼───────┼────────┼───┼────────┼─────┼─────────┤ ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.