The daemon under Linux daemon

Source: Internet
Author: User

What is a daemon process? In fact, there is no clear definition of the daemon process, but there are some characteristics of the daemon, which is what it needs to follow.

The first feature of a daemon is a program that runs in the background for a long time, and is primarily designed to provide a service, and in order for the service to be available whenever possible, the service is required to be running, and the daemon is guarding the service from hanging. Common daemons in Linux typically end with D, such as Apache's Httpd,samba smbd,ssh sshd.

Its second feature is the environment isolation from the process that initiated it, including closing all file descriptors, terminals, sessions, process groups, certain environment variables (such as working directory), and file masks.

    Why get out of the terminal?

If it is not out of the terminal, then it is possible to receive signals from the terminal, such as SIGINT (CTRL + C, will be sent to all foreground process groups, its default behavior is to end the process), SIGHUP (will be sent to the session first process).

    Why would you want to close all the file descriptors it opened?

If the process of creating it opens a file and then creates the daemon, the process inherits the FD, and if the daemon does not close the FD, one will take up resources, two I guess and change the working directory, if the file is located in the Mount directory, then it cannot be umount.

    Why should I clear the mask?

This is because assuming that its parent process has made a special provision to the mask before, the daemon inherits this as a child process, and when it creates the file, the file's permissions may be inconsistent with the actual settings because of the mask.

Third feature, daemons are typically started by a startup script

  

From the Apue Daemon Chapter example, a process daemon code:

-----

Or use a Linux ready-made function, daemon.

The daemon under Linux daemon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.