[Switch] daemon instance implemented in C language-destinydesigner-blog Garden
[Switch] daemon instances implemented in C Language
Daemon is a special process running in the background. It is independent of the control terminal and periodically
This chapter needs to master the following several functions Fork,exec family, _exit,wait,waitpid1 Process Identifiers#include pid_t getpid (void); Returns:ProcessId ofCallingProcesspid_t getppid (void); Returns:parentProcessId ofCallingProcessuid_t
This document shows how to write a daemon in Linux using gcc. knowledge of Linux and a familiarity with C are necessary to use this document. this howto is copyright by Devin Watson, under the terms of the BSD license.
1. Introduction: What is a
1. Wait for the process to exit
In Linux, the wait function is used to obtain the end information of the sub-process. The function prototype is as follows:
# Include
Pid_t wait (int * statloc );
The function that calls wait is blocked until any
#include ;#include ;main (){ pid_t pid; pid=fork(); if (pid else printf("i am the parent process, my process id is %d/n",getpid());}
The result is[Root @ localhost C] #./A. OutI am the child process, my
Piping ConceptsPipelines are the oldest form of interprocess communication in Unix, and we refer to a data flow from one process to another as a "pipe", the essence of which is a fixed-size kernel buffer ;such as: PS aux | grep httpd | awk ' {print $
15, Guardian ProcessConcept:A daemon (Daemon) is a special process that runs in the background. It is independent of the control terminal and periodically performs some sort of task or waits to handle certain occurrences.features of the daemon:The
Linux inter-process communication (IPC) programming practices (I) Basic concepts and anonymous Pipelines
Inter-process communication can be achieved at least by sending open files. Different processes transmit information through one or more files.
Fork () and vfock () Both create a process. What is the difference between them? There are three differences:1. Fork (): The child process copies the data segment of the parent process, code segmentVfork (): The child process shares the data segment
Fork introduction:Fork stands for the meaning of "branching and branching". In the operating system, fork is a famous Unix (or Unix-like, such as Linux or minix) to create a sub-process.
[Note1]What is the role of Fork? In other words, what is the
Example 4:/* interaction between parent and child processes: the parent process writes from parent process to the child process, and the child process writes from child process to the parent process */
ReferencesHttp://kenby.iteye.com/blog/1166111
Environment variable Operation function
Char*getenv (const char* name); Get environment variable value
Intputenv (cahr* str); A string of name=value, put it in the environment table, and delete its original definition if name already
The Linux programming-Daemon Authoring Daemon (Daemon) is a special process that runs in the background. It is independent of the control terminal and periodically performs some sort of task or waits to handle certain occurrences. Daemons are a
Fork introduction:Fork stands for the meaning of "branching and branching". In the operating system, fork is a famous Unix (or Unix-like, such as Linux or minix) to create a sub-process.
[Note1]What is the role of Fork? In other words, what is the
Author: CCF published on: 17:11:01
# Include ;
# Include ;
Main ()
{
Pid_t PID;
PID = fork ();
If (PID
Printf ("error in fork! ");
Else if (pid = 0)
Printf ("I am the child process, my process ID is % DN", getpid ());
Else
Printf ("I am the
Finally, I began to learn about the apue Process Management chapter. In fact, I have read a book, read it, and read it carefully. However, we do not have much time to read words one by one, so we need to identify them. You can only view what you are
1. basic concepts involved in Daemon 1.1 Process Group 1.1.1 Process Group basic concepts process groups are a collection of one or more processes that can receive various signals from the same terminal. Each running program or command generates a
several ways to terminate a process(1) Normal exitreturn from main function [Return] Call exit Call _exit/_exit(2) Abnormal exit call Abort to generate Sigabout signal terminated by signal CTRL + C [SIGINT] ... (not completely, such as
One, the process replicates (or produces)The child processes obtained by using the fork function inherit the entire process's address space from the parent process, including: process context, process stack, memory information, open file descriptor,
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.