Linux Application Development-Daemon
Linux application Development-Daemon
A daemon process
Default running process in the background
Two links to Android's services
Three-daemon process writing
1 out of control terminal TTY, let parent process be init
2 Disable process re-opening control terminal
3 re-open session setsid ();
4 Closes the open file descriptor, where the process inherits the open file descriptor from the parent process that created it
, failure to shut down will result in resource wastage, resulting in the inability of the filesystem to unload and cause unforeseen errors
You can use the For loop to close
for (i = 0; i < number of file descriptors; i++)
{
Close (i);
}
5 Changing the current working directory
Process activity is that the file system in which the working directory resides cannot be written down, and it is generally necessary to change the working directory to the root directory
chdir ()
6 reset umask (0)
Process from the creation of his parent process where the file creation mask continues, it may modify the village interest of the file created by the daemon
7 Modify RC file or Inittab file, can boot automatically
8 Results
Four kills the daemon process
Kill PID (with permissions)
Support for the five daemon processes
1 Core services are usually executed in a separate process
2 The application must be allowed to process communication across processes
3 multithreading security must be ensured because of sharing
4 Life cycle Management (SM)
Linux Application Development-Daemon