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
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:
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