Services & Processes on CentOS/RHEL/Debian/Ubuntu

Services & Processes on CentOS/RHEL/Debian/Ubuntu

Its Really Necessary for an administrator to be aware of the services running in a server.Sometimes it becomes a tedious task to deal with this part.

Here in this post we have discussed an easy way with which even a novoice user can deal with system services.

  • There are two ways to check the status of an installed service:-
1. # service service-name status

Example:- [root@centos ~]# service httpd status httpd (pid 4404) is running...
2. # /etc/init.d/service-name  status

Example:- [root@centos ~]# /etc/init.d/httpd status httpd (pid 4404) is running...
  • In order to check status of all Installed services, use below command:-
[root@centos ~]# service --status-all

 It will display a long list of installed services & their status

---------

---------

abrt-dump-oops is stopped

acpid (pid  1519) is running...

atd (pid  4966) is running...

auditd (pid  4668) is running...

automount (pid  1595) is running...

Usage: /etc/init.d/bluetooth {start|stop}

certmonger (pid  4991) is running...

cpuspeed is stopped

crond (pid  4954) is running...

cupsd (pid  1508) is running...

dnsmasq is stopped

exim (pid  1817) is running...

firstboot is not scheduled to run

hald (pid  1528) is running...

htcacheclean is stopped

httpd (pid  4404) is running...

-----------

-----------

With such a huge output, sometimes it becomes difficult to traceout a particular service, In order to avoid this we can use below commands:-

  • ps & pgrep are two commonly used commands that helps in checking services & their status
#ps aux | grep service-name

Example:-

[root@centos ~]# ps aux | grep httpd
root   4404 0.0 0.0 317380 780 ? Ss 11:35 0:00 /usr/sbin/httpd 
apache 4414 0.0 0.0 317380 332 ? S 11:35 0:00 /usr/sbin/httpd
apache 4415 0.0 0.0 317380 332 ? S 11:35 0:00 /usr/sbin/httpd
apache 4416 0.0 0.0 317380 332 ? S 11:35 0:00 /usr/sbin/httpd
apache 4417 0.0 0.0 317380 332 ? S 11:35 0:00 /usr/sbin/httpd
apache 4418 0.0 0.0 317380 348 ? S 11:35 0:00 /usr/sbin/httpd
apache 4419 0.0 0.0 317380 332 ? S 11:35 0:00 /usr/sbin/httpd
apache 4420 0.0 0.0 317380 332 ? S 11:35 0:00 /usr/sbin/httpd
apache 4421 0.0 0.0 317380 332 ? S 11:35 0:00 /usr/sbin/httpd
root 6782 0.0 0.0 103248 820 pts/1 S+ 12:02 0:00 grep httpd
 
#pgrep service-name

Example:-

[root@centos ~]# pgrep httpd
4404
4414
4415
4416
4417
4418
4419
4420
4421

You can also check the service with its corresponding user

#pgrep -u  user-name  service-name

Example:-

[root@centos ~]# pgrep -u apache httpd
4414
4415
4416
4417
4418
4419
4420
4421
  • START/STOP a Service
# service service-name start/stop/restart/reload

Example:-

[root@centos ~]# service httpd start
Starting httpd:
[root@centos ~]# service httpd status
httpd (pid 4404) is running...
[root@centos ~]# service httpd stop
Stopping httpd: [ OK ]
[root@centos ~]# service httpd status
httpd is stopped
# /etc/init.d/service-name  start/stop/restart/reload

Example:- 
[root@centos ~]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]
[root@centos ~]# /etc/init.d/httpd start
Starting httpd: [ OK ]
[root@centos ~]# /etc/init.d/httpd status
httpd (pid 7093) is running...
 

How to Kill a Process?

There are different ways to kill a process in Linux. Here we’ve discussed kill, killall & pkill command.

  • Kill Command :- Kill Command is basically used to kill a process or to send signal to a process.
#kill  -Signal/Value  pid 

Signal/Value can be any of the below as per the requirement

SIGNAL VALUE EFFECT
SIGHUP 1 Hangup Signal
SIGINT 2 Interrupt Signal
SIGKILL 9 Kill Signal
SIGTERM 15 Terminate Signal
SIGSTOP 17/19/23 Stop Signal

Example:- Suppose we want to kill a process with process id 7567, we can use any of the below command

[root@centos ~]# kill -9 7567

or

[root@centos ~]# kill -SIGKILL 7567
  • killall Command:- killall Command is used when there are more than one process running with same name
#killall  -Signal/Value  name-of-process 

Example:- Suppose if there are multiple processes running with same name, we can use any of the below command to kill all instances of that process.

[root@centos ~]# killall -9 chromium

or

[root@centos ~]# killall -SIGKILL chromium
  • pkill Command:- pkill Command is used to kill a process by mentioning its name
#pkill -Signal/Value   name-of-process

Example:- Suppose we want to kill a process named firefox

[root@centos ~]# pkill -9 firefox

or

[root@centos ~]# pkill -SIGKILL firefox

Note:- If we use this command like  pkill  firefox i.e without mentioning any Signal/Value, then it will send  SIGTERM/15 as a default Signal/Value.

 

*************************************************END-OF-POST**************************************************

Leave a Reply

Time limit is exhausted. Please reload the CAPTCHA.