Linux Guard Service-the role, purpose, and characteristics of the parent process identity of the daemon

Source: Internet
Author: User
Tags gtk

Let Test2 directly become the Guardian process
[[email protected] 02]# cat test2.c //test2#include<stdio.h>#include<unistd.h>#include<fcntl.h>#include<sys/stat.h>#include<stdlib.h>int main(){        if(daemon(1,1)==-1){                perror("daemon error");                exit(EXIT_FAILURE);        }        int i=0;        while(1){                FILE *fd=fopen("test2.log","a");                fprintf(fd,"%d 1552227\n",i++);                sleep(1);                fclose(fd);        }        return 0;}[[email protected] 02]#

The execution of Test2 has become a test2.log file, and the constantly updated test2.log indicates that it is constantly running

32 155222733 155222734 155222735 155222736 155222737 155222738 155222739 155222740 1552227[[email protected] 02]#

Exit the current terminal, ( no longer prompted for a task in progress ) to enable the new terminal, and then observe Test2.log

The discovery program is still performing normally

Use

View All Daemons

  2761 ?        Sl     0:00  \_ /usr/libexec/evolution-addressbook-factory-subpr  2766 ?        Sl     0:00 /usr/libexec/ibus-x11 --kill-daemon  2837 ?        Sl     0:00 /usr/libexec/gvfsd-network --spawner :1.4 /org/gtk/g  2852 ?        Sl     0:00 /usr/libexec/gvfsd-dnssd --spawner :1.4 /org/gtk/gvf  9158 ?        Ss     0:00 ./test2  9187 ?        Sl     0:00 /usr/sbin/abrt-dbus -t133[[email protected] 02]#

./test2 is a top-level process with no parent process ( unlike the previous-bash as the parent process )

To print information in the process, you can use the method that is output to log, but note the points

    1. Write the file close every time, otherwise it is not written in
    2. To control the program write log, otherwise it will produce a GB of text log, multiple write log programs can run at the same time may be down the system

Linux Guard Service-the role, purpose, and characteristics of the parent process identity of the daemon

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.