DAEMON(7) daemon DAEMON(7) daemon - . SysV. ( " ") systemd(1). init systemd. SysV SysV . ( ) SysV . 1. ( 0 1 2). . /proc/self/fd 3 getrlimit() RLIMIT_NOFILE. 2. . _NSIG SIG_DFL. 3. sigprocmask(). 4. . 5. fork() . 6. setsid() . 7. fork() . ( -- -- `O_NOCTTY` `open()` TTY.) 8. exit() ( ). init/PID 1 . 9. /dev/null . 10. umask 0 open() mkdir() . 11. (/) . 12. PID ( getpid()) PID /run/foobar.pid ( "foobar") . PID PID PID . 13. . 14. . fork() . 15. exit() . exit() . BSD daemon() . SysV . systemd. . . SysV. init systemd . . : . /dev/null / systemd-journald.service(8) . umask. : 1. sd_notify(3) READY=1 STATUS=.... 2. SIGTERM . STOPPING=1 sd_notify(3). 3. SIGHUP . sd_notify(3): RELOADING=1 READY=1. 4. . LSB SysV[1]. 5. D-Bus IPC . 6. systemd .service . systemd.service(5) . 7. systemd systemd systemd . systemd.exec(5) . 8. D-Bus D-Bus. : -- . . 9. . D-Bus . ( syslog DNS) . . 10. sd_notify(3) FDSTORE=1. 11. syslog() syslog fprintf() syslog. "<4>" ( 4 "WARNING" syslog) printk() . sd-daemon(3) systemd.exec(5). 12. TTY ( ) O_NOCTTY open(2) TTY TTY . Apple MacOS X[2]. . . systemd: bluetoothd.service D-Bus. IPP . . D-Bus ( ) ( D-Bus) ( ) . ( ) SysV LSB [1]. SysV . . . systemd .wants/ multi-user.target graphical.target . systemd.unit(5) .wants/ systemd.special(7) . . ( ) . . . . ( DNS syslog) . . systemd sd_listen_fds(3) sd-daemon(3). . init . systemd .socket systemd.socket(5). sockets.target. WantedBy=sockets.target [Install] . DefaultDependencies=no . sockets.target systemd.special(7). ( multi-user.target ) sockets.target. IPC D-Bus IPC . D-Bus ( systemd!). D-Bus systemd SystemdService= systemd D-Bus. : D-Bus D-Bus org.freedesktop.RealtimeKit.service SystemdService=rtkit-daemon.service systemd rtkit-daemon.service. . . init / . systemd sysfs/udev "systemd". ( ) . systemd udev SYSTEMD_WANTS=. systemd.device(5) . . : bluetoothd.service bluetooth.target bluetoothd.service . bluetoothd.service bluetooth.target.wants/ enable systemctl(1) udev. ( ) . init . systemd .path systemd.path(5). . systemd .timer systemd.timer(5). . . : .socket IP . Linux IP_FREEBIND/IPV6_FREEBIND FreeBind=yes systemd ( systemd.socket(5) ). IP IP . . CPU I/O Linux. . systemd CPU I/O. / CPUSchedulingPolicy=idle / IOSchedulingClass=idle. . SYSTEMD systemd systemd : 1. Type=forking . PID PIDFile=. systemd.service(5) . 2. D-Bus Type=dbus . 3. Description=. 4. DefaultDependencies= . 5. . systemd.special(7) . 6. [Install] . systemd.unit(5) . WantedBy=multi-user.target WantedBy=graphical.target. WantedBy=sockets.target. Also=foo.socket foo.service foo. systemd ( make install ) systemd pkg-config systemd --variable=systemdsystemunitdir ( ) pkg-config systemd --variable=systemduserunitdir ( ). . ( rpm -i ) systemd enable systemctl(1) . autoconf(1) : PKG_PROG_PKG_CONFIG() AC_ARG_WITH([systemdsystemunitdir], [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],, [with_systemdsystemunitdir=auto]) AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [ def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd) AS_IF([test "x$def_systemdsystemunitdir" = "x"], [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"], [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])]) with_systemdsystemunitdir=no], [with_systemdsystemunitdir="$def_systemdsystemunitdir"])]) AS_IF([test "x$with_systemdsystemunitdir" != "xno"], [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])]) AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"]) systemd systemd. ( .) make distcheck Makefile.am automake(1): AM_DISTCHECK_CONFIGURE_FLAGS = \ --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) : if HAVE_SYSTEMD systemdsystemunit_DATA = \ foobar.socket \ foobar.service endif rpm(8) .spec / / . RPM systemd. . : BuildRequires: systemd %{?systemd_requires} : %post %systemd_post foobar.service foobar.socket %preun %systemd_preun foobar.service foobar.socket %postun %systemd_postun "%postun" : %postun %systemd_postun_with_restart foobar.service "%systemd_post" "%systemd_preun" / . "%systemd_postun" . "%systemd_postun_with_restart" . SysV init SysV init systemd : %triggerun -- foobar < 0.47.11-1 if /sbin/chkconfig --level 5 foobar ; then /bin/systemctl --no-reload enable foobar.service foobar.socket >/dev/null 2>&1 || : fi 0.47.11-1 . SysV init . chkconfig Fedora SysV init . . init systemd SysV init . init . SysV : 1. . init . 2. AF_UNIX ( ). : sd_listen_fds(3) . ( sd_listen_fds() ) . AF_UNIX . . init . 3. systemd ( ) . 4. D-Bus D-Bus . file-hierarchy(7). "MIT No Attribution" (SPDX-License-Identifier: MIT-0). systemd(1) sd-daemon(3) sd_listen_fds(3) sd_notify(3) daemon(3) systemd.service(5) file-hierarchy(7) 1. LSB SysV http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html 2. Apple MacOS X https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html 3 . . : . systemd 260.2 DAEMON(7)