How to check if a particular service is running on Ubuntu?


We know that we can make use of the top command to print all the processes that are running in the background. Though the top command is used to print the list of processes or threads that are currently managed by the Linux kernel, it is still not a convenient way to check if a particular service is running in the background or not.

In order to understand how to check whether a particular service is running or not, we first must understand what a service actually means in Linux. A service is basically a process or group of processes that is running continuously in the background.

Now we know what a service is, next is to get an idea about the different commands that we will make use of to check whether a particular service is running or not.

The first command is the ps command of the Linux operating system. The ps command is short for “process status” and is used to list the currently running processes on your Linux machine along with their PIDs and different options.

Syntax

ps ef | [ - options ]

Let’s make use of two examples where first we will print all the processes that are running on your ubuntu machine, and next we will print whether a specific service is running or not.

Command

ps ef

Output

UID   PID   PPID   C STIME   TTY   TIME CMD
 0     1     0 0 25Jun21 ??      19:53.44 /sbin/launchd
 0    56     1 0 25Jun21 ??       0:41.68 /usr/sbin/syslogd
 0    57     1 0 25Jun21 ??       0:59.28 /usr/libexec/UserEventAgent (System)

The output of the above command is huge so I printed only a chunk of it, and it should be noted that the output can vary.

Command

ps -ef | grep Terminal

The above command will tell us whether a particular service is running on your machine or not. In the above command I am checking whether the Terminal service is running or not.

Output

501 28604 1 0 Sun12PM ?? 2:43.95
/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal

501 45775 45479 0 9:31AM ttys000 0:00.01 grep Terminal

Only if you see the CMD column of the above output filled with the command, then you can confirm that the service is actually running.

Another way to check whether a service is running or not is to make use of the aux command in place of the -ef flag in the above commands.

Command

ps aux | grep Terminal

Output

immukul@192 linux-questions-code % ps aux | grep Terminal
immukul 28604 3.3 0.7 5429432 57080 ?? S Sun12PM 2:46.14
/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal

immukul 45869 0.0 0.0 4268300 520 s000 R+ 9:44AM 0:00.00 grep
Terminal

Updated on: 29-Jul-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements