Daemon in Linux

Daemon in Linux

What is Daemon ?

A daemon in Linux is a silent worker that performs essential tasks in the background without disturbing . It operates on the computer, managing activities such as internet connections, printing files, and maintaining accurate system time. While you may not be aware of it, daemons play a crucial role in ensuring your computer functions smoothly.

Linux servers host network applications that assist clients and network devices. These applications, referred to as services, are initiated by the server autonomously, without human intervention. When services on a Linux server can self-start, they are termed daemons. Daemons operate discreetly in the background, ready to respond to client connection requests. Additionally, a super-server functions behind the scenes, managing connection requests for multiple services. Upon accepting a request, the super-server initiates the appropriate service.

Characteristics of Daemons

  1. Background Operation: Daemons work silently in the background, carrying out tasks without needing user input.

  2. Autostart: Normally, daemons start automatically when the system boots up and keep running until the system is shut down.

  3. Resource Management: They effectively handle system resources like CPU time, memory, and disk space to complete their assigned tasks.

  4. Persistence: Daemons run continuously in the background, ensuring that services stay accessible for users and other applications.

  5. Independence: They can function independently of user sessions, running even when no users are logged into the system.

Examples of Daemons

  • Web Servers: Daemons like Apache HTTP Server or Nginx serve web pages to users who request them through web browsers.

  • Email Servers: Daemons such as Postfix or Sendmail handle the sending and receiving of emails on mail servers.

  • Print Spoolers: Daemons like CUPS manage print jobs sent from user applications to printers.

  • System Monitoring: Daemons like systemd or cron perform system monitoring and automation tasks, such as scheduling periodic tasks or managing system services.

Command lines

ps

We can use the ps command with options to display a list of running processes, including daemons:

bashCopy codeps aux | grep daemon

This command lists all processes (including daemons) and filters the output to show only those containing the word "daemon."

Let's take an example:

Daemon Name: httpd (Apache HTTP Server Daemon)

Function: httpd helps serve web pages and handle requests on a Linux server.

  1. Start:

     sqlCopy codesudo systemctl start httpd
    

    This starts the Apache HTTP Server.

  2. Stop:

     arduinoCopy codesudo systemctl stop httpd
    

    This stops the Apache HTTP Server.

  3. Restart:

     Copy codesudo systemctl restart httpd
    

    This restarts the Apache HTTP Server.

  4. Check Status:

     luaCopy codesudo systemctl status httpd
    

    This checks if the Apache HTTP Server is running.

  5. Enable Auto Start:

     bashCopy codesudo systemctl enable httpd
    

    This makes the Apache HTTP Server start automatically when the system boots up.

  6. Disable Auto Start:

     bashCopy codesudo systemctl disable httpd
    

    This stops the Apache HTTP Server from starting automatically when the system boots up.

Summary: httpd is a daemon that serves web pages on a Linux server. You can start, stop, restart, check its status, and configure whether it starts automatically using these commands.