Linux Daemon 的雛型

本篇文章是紀錄 Linux Daemon 撰寫的雛型,程式碼引用自 Fred 的 Blog。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    pid_t pid;
    pid = fork();
    
    // If pid > 0, the process is the parent process and will be killed.
    // If pid = 0, the process is the child process.
    
    if ( pid > 0 ) 
    {
        exit(0);
    }

    while(1) 
    {
        // Infinite loop for the child process which will be executed in the background.
    }
    
    return 0;
}

程式碼很簡單,就不加以說明了。紀錄在這邊純粹方便之後的修改。

留言

這個網誌中的熱門文章

我弟家的新居感恩禮拜分享:善頌善禱

如何將Linux打造成OpenFlow Switch:Openvswitch

Openssl 範例程式:建立SSL連線