How to check if a service that I don't know the name of is running on Ubuntu

LinuxPostgresqlServiceUbuntu 12.04

Linux Problem Overview


I do not know the service's name, but would like to stop the service by checking its status.

For example, if I want to check if the PostgreSQL service is running or not, but I don't know the service's name, then how could I check its status?

I know the command to check the status if the service name is known.

Linux Solutions


Solution 1 - Linux

I don't have an Ubuntu box, but on Red Hat Linux you can see all running services by running the following command:

service --status-all

On the list the + indicates the service is running, - indicates service is not running, ? indicates the service state cannot be determined.

Solution 2 - Linux

For Ubuntu (checked with 12.04)

You can get list of all services and select by color one of them with 'grep':

sudo service --status-all | grep postgres

Or you may use another way if you know correct name of service:

sudo service postgresql status

Solution 3 - Linux

Maybe what you want is the ps command;

ps -ef

will show you all processes running. Then if you have an idea of what you're looking for use grep to filter;

ps -ef | grep postgres

Solution 4 - Linux

There is a simple way to verify if a service is running

systemctl status service_name

Try PostgreSQL:

systemctl status postgresql

Solution 5 - Linux

If you run the following command you will get a list of services:

sudo service --status-all

To get a list of upstart jobs run this command:

sudo initctl list

Solution 6 - Linux

You can use the below command to check the list of all services.

ps aux 

To check your own service:

ps aux | grep postgres

Solution 7 - Linux

the best way is using of nmap tool in terminal. nmap is an useful tool that analyse an up system, using it's IP Address, then show all actived network services.

open terminal and use of this example :

~$ nmap 192.168.1.3/24

Starting Nmap 5.21 ( http://nmap.org ) at 2016-05-16 22:49 IRDT
Nmap scan report for 192.168.1.3
Host is up (0.00020s latency).
Not shown: 994 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
23/tcp   open  telnet
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
3389/tcp open  ms-term-serv
3689/tcp open  rendezvous

Solution 8 - Linux

run

ps -ef | grep name-related-to-process

above command will give all the details like pid, start time about the process.

like if you want all java realted process give java or if you have name of process place the name

Solution 9 - Linux

To check the status of a service on linux operating system :

//in case of super user(admin) requires    
sudo service {service_name} status 
// in case of normal user
service {service_name} status 

To stop or start service

// in case of admin requires
sudo service {service_name} start/stop
// in case of normal user
service {service_name} start/stop 

To get the list of all services along with PID :

sudo service --status-all

You can use systemctl instead of directly calling service :

systemctl status/start/stop {service_name}

Solution 10 - Linux

Dirty way to find running services. (sometime it is not accurate because some custom script doesn't have |status| option)

[root@server ~]# for qw in `ls /etc/init.d/*`; do  $qw status | grep -i running; done
auditd (pid  1089) is running...
crond (pid  1296) is running...
fail2ban-server (pid  1309) is running...
httpd (pid  7895) is running...
messagebus (pid  1145) is running...
mysqld (pid  1994) is running...
master (pid  1272) is running...
radiusd (pid  1712) is running...
redis-server (pid  1133) is running...
rsyslogd (pid  1109) is running...
openssh-daemon (pid  7040) is running...

Solution 11 - Linux

For centos, below command worked for me (:

locate postgres | grep service

Output:

/usr/lib/firewalld/services/postgresql.xml

/usr/lib/systemd/system/postgresql-9.3.service

sudo systemctl status postgresql-9.3.service

Solution 12 - Linux

for Centos 6.10 : /sbin/service serviceNAME status

for Centos 7.6 and ubuntu 18.04: systemctl status NAME.service

works for all of them: service --status-all

Solution 13 - Linux

Based on this answer on a similar topic https://askubuntu.com/a/58406
I prefer: /etc/init.d/postgres status

Solution 14 - Linux

if you are looking particularly for postgres there is a specific command called "pgrep" you can find the usage in the below mentioned article https://mydbanotebook.org/post/troubleshooting-01/

this article provides the following details: check if postgres server is running where does postgres store all the server config how to start/stop postgres

hope this is helpful

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionabcdView Question on Stackoverflow
Solution 1 - LinuxRaduView Answer on Stackoverflow
Solution 2 - LinuxzhecsanView Answer on Stackoverflow
Solution 3 - LinuxMike MakuchView Answer on Stackoverflow
Solution 4 - LinuxAngelView Answer on Stackoverflow
Solution 5 - LinuxlinuxnewbeeView Answer on Stackoverflow
Solution 6 - LinuxAmey JadiyeView Answer on Stackoverflow
Solution 7 - LinuxBattleTested_закалённый в боюView Answer on Stackoverflow
Solution 8 - LinuxInder malviyaView Answer on Stackoverflow
Solution 9 - LinuxYAPView Answer on Stackoverflow
Solution 10 - LinuxSatishView Answer on Stackoverflow
Solution 11 - LinuxWalkView Answer on Stackoverflow
Solution 12 - LinuxTeyaView Answer on Stackoverflow
Solution 13 - LinuxtschomackerView Answer on Stackoverflow
Solution 14 - LinuxShivachandraView Answer on Stackoverflow