How To Start / Stop Daemons In Linux

What is a Daemon?

A 'daemon' (or you may call it a service) is a program designed to run in the background without the user's control. Daemons are a type of process recognized by a system whose parent process is init with PID 1. For all UNIX and Linux distributions, by default, init starts as the first process after booting up the system. A daemon consists of a series of actions. In order to develop daemon, you need to have the gcc packages installed on your Linux machine.

The daemons listed in /etc/init.d are configured to be run as Linux services. These services start or stop through the init scripts in the /etc/init.d directory. Many of these services start when the system is booted.

Syntax to start/stop/restart any daemon

#service start/stop/restart
Or,
#/etc/init.d/daemon-name start/stop/restart

You can use the ls command to find out which daemons are available on the system.

#ls -l /etc/init.d

You can view the current state of all the services with the help of the service command as follows:

#service --status-all
acpid (pid 2481) is running...
anacron (pid 2647) is running...
atd (pid 2657) is running...
auditd (pid 2189) is running...
....

You can use 'chkconfig' utility to start daemon at a different run level. For example, use chkconfig utility to query the current settings for the syslog service.

#chkconfig --list syslog
syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off

The output above shows that the syslog service will automatically start at the time of booting for runlevels 2, 3, 4, and 5.

Now, to stop the service for runlevels 3 and 4, you can use the following options for the chkconfig utility:

#chkconfig –levels 34 syslog off

If you want to make sure whether a daemon is running or not, you can use the 'ps' command with grep option.For example, if you want to check whether the anacron daemon has really started or not:

#ps -aux | grep anacron

Bobbin Zachariah 5:47 pm

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.