I was asked about killing a process in an interview and my answer was close, but not quite correct. I realized it wasn’t correct when I found myself actually having to do it just days later. Let’s say you have a node app running that you want to kill.

ps aux | grep "node"

ps aux will list all processes. We pipe it into grep to find our node process.

kill pid

The kill command kills the process. pid is a placeholder for the actual process id that we get from ps aux

This has been a quick-n-dirty guide to finding and killing a process.

UPDATE: I found an even easier way to kill processes. The pidof command will find the pid of a process. You may have to brew install pidof or apt-get install pidof if you don’t have it, but once you do then running the following command will show you the pid of your node app.

pidof node

This may give you multiple pid’s if multiple node apps are running. You can kill them all with one simple command.

kill $(pidof node)

UPDATE: Yet another very easy way to kill a process

$ pgrep node
93498
$ kill 93498

Advertisements

One thought on “Killing a process

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s