2. Standard input, standard output, and standard error are redirected to /dev/null
The daemon implementation is roughly as follows:
< Pre>int daemonize(int nochdir, int noclose) { int fd; switch (fork()) { case -1: return (-1); case 0: break; default: _exit(EXIT_SUCCESS); } if (setsid() == -1) return (-1); if (nochdir == 0) { if(chdir("/") != 0) { perror("chdir"); return (-1); } } If (noclose == 0 && (fd = open("/dev/null", O_RDWR, 0)) != -1) { if(dup2(fd, STDIN_FILENO) < 0) { perror(" ;dup2 stdin"); return (-1); } if(dup2(fd, STDOUT_FILENO) < 0) { perror("dup2 stdout"); return (-1); } if(dup2(fd, STDERR_FILENO) < 0) { perror("dup2 stderr"); return (-1); } if (fd > STDERR_FILENO) { if(close(fd) < 0) { perror("close"); return ( -1); } } } return (0);} So, if you want to retrieve the console data of the process, just put the standard output Standard error is redirected to the specified file, and then read the file just fine. The article here writes an example, a simple demonstration (here through the kill signal to complete the process communication, a bit rough) code is as follows, saved as daemon_example.c
#include #include #include #include static int fd = -1;void sigroutine (int dunno) { switch (dunno) { case SIGUSR1: fprintf(stderr, "Get a signal -- SIGUSR1 \ "); if (fd != -1) close(fd); fd = open("/Tmp/console_temp.log", O_RDWR
What should I do if the Ubuntu system Grub fails? Many computer users think of reloading: Grub, howe
ls is simply a list of file names in the directory, ll more detailed list of file types, file owner
1 dr mode introduction 1.1 lvs installation 1.2 lvs mode lvs has three modes dr, nat, tun
Linux Regular Expressions - Wildcards
How the linux route command works
9 Linux commands that must be carefully used before use
Character encoding and conversion tool for files under GnuLinux
Ubuntu - grubrescue master boot fix
[linux study notes] swap virtual memory add and delete configuration
Win10 RS1 preview version 14271 task bar now white frame arrow?
Three steps to get XP DLL file error when prompted to boot
Getting Started: Learning Hard Disk Partitioning and Sizing
Introduction to grep regular expressions in Linux system
What should I do if the memory usage of WinXP computer is too high?
Reasonable setting of Vista's six common problems to solve
How does Win7 open the registry? Win7 system to open the registry skills
Microsoft: Windows 8 installation time will be significantly shortened