Ask Steves · Daily notes · VPS, 20% off · AI Profit Lab · SEO · Money Hub

18 October 2026 · One command a day

How do I rerun a command every 2 seconds on Linux?

The watch command runs another command again and again at a fixed interval. It shows the latest output full screen each time. If you pair it with pm2 list, you get a live view of your Node apps that refreshes every 2 seconds. Use it after a deploy or a restart, when you want to see whether an app stays up or keeps crashing.

I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.

The command

watch -n 2 "pm2 list"

watch runs the command you give it, clears the screen and runs it again. -n 2 sets the interval in seconds. The default is already 2, so writing it out just makes the intent clear. You can set any value down to 0.1. The quotes around pm2 list pass it as a single command. This matters as soon as you add pipes or extra options. Run it as the same user that owns your PM2 apps, without sudo. Press Ctrl+C to stop.

What you will see

Every 2.0s: pm2 list                      host: Sun Oct 18 10:15:02 2026

┌────┬─────────────┬─────────┬────┬───────────┬──────────┬──────────┐
│ id │ name        │ mode    │ ↺  │ status    │ cpu      │ memory   │
├────┼─────────────┼─────────┼────┼───────────┼──────────┼──────────┤
│ 0  │ appname     │ fork    │ 0  │ online    │ 0.3%     │ 68.2mb   │
│ 1  │ sitename    │ cluster │ 2  │ online    │ 1.1%     │ 92.4mb   │
│ 2  │ worker      │ fork    │ 17 │ errored   │ 0%       │ 0b       │
└────┴─────────────┴─────────┴────┴───────────┴──────────┴──────────┘

The top line shows the interval, the command, the hostname and the time of the last run. Below it is the normal PM2 table, drawn again on each run. Two columns matter most. status should say online. If a row keeps switching between launching, online and errored, the app is in a crash loop. The ↺ column counts restarts. If that number goes up while you watch, the app keeps dying and PM2 keeps starting it again, as with worker above. If memory rises on every refresh, the app may have a leak.

When to use it

Watch out for

PM2 runs a separate daemon for each Linux user. Say you started your apps as a normal user and then run sudo watch -n 2 "pm2 list". You are now looking at root's PM2, which is usually empty or shows different apps. Your apps are fine. You are just asking the wrong daemon. Drop the sudo, or switch to the right user first. If you are not sure what the list should contain, the note on seeing all your Node apps under PM2 explains the table itself.

Questions people ask

Can watch highlight what changed between refreshes?

Yes. Add -d, as in watch -d -n 2 "pm2 list", and anything that changed since the last run is highlighted.

Does running pm2 list every 2 seconds slow the server down?

Not in any way you would notice. pm2 list is a quick query to the PM2 daemon. Still, close it when you are done rather than leaving it open for hours.

Watching your own process manager live like this is something you can only do on a server you control, with shell access. You can get the same VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.

Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.

Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.

GET A VPS, 20% OFF →

Affiliate link.

Related server notes: How do I see all my Node apps running under PM2? · How do I restart one app with PM2 after a deploy? · How do I find what is using disk space on Linux? · All daily notes