Linux Guard Service-Daemon splits child process again

Source: Internet
Author: User
Tags pkill

The maximum number of sub-processes allocated in 512MB memory will fail when the system area memory is no longer requested for a new process

3331

[[email protected] 05]# ./test5-1 50000expect 50000 sub process[[email protected] 05]# 1000 sub process attributed1000 sub process attributed1000 sub process attributedpid attribute failed!Total sub process 3331 [[email protected] 05]# pkill test5-1
Maximum number of sub-processes allocated in 1024MB memory

7364

Maximum number of sub-processes allocated in 1024MB memory

14106

[[email protected] 05]# ./test5-1 50000expect 50000 sub process[[email protected] 05]# 1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributed1000 sub process attributedpid attribute failed!Total sub process 14106     

Because the child process and the parent process share some of the variables between fork (), logging the maximum PID in a child process can be read in the parent process.

last_pid=getpid();......fprintf(pfile,"mainline staying\n");
Allow the sub-process to split over the system under small memory conditions

Use queued methods to wait for the old process to finish

signal(SIGCHLD,SIG_IGN);

Automatically released, and then in the parent process

while(pid<0){        sleep(1);        printf("Waiting old process abort...\n");        pid=fork();}

Keep waiting, you can queue up for all processes

If the process is system-level, queuing can cause-bash access difficulties, such as

[email protected] 05]# pkill test5-2

This multithreaded instruction may appear to be unresponsive for a short period of time (prompting Bash Fork), but instructions are saved in the terminal input queue, and the operating system will "wait" to complete this instruction using two variable records to release the child process and reclaim the child process

If you want to record the number of free child processes, you can no longer use the signal channel function, instead

pid_t waitpid(-1,NULL,WNOHANG);

In the dead loop of the parent process, this function is repeatedly set to reclaim the zombie process

else{        printf("Total sub process %d \n",att);        printf("last pid is %d\n",pid);        while(1){                if(waitpid(-1,NULL,WNOHANG)>0) sub_abor++;                printf("sub attr:%d, sub abor:%d\n",sub_attr,sub_abor);                pfile=fopen("test5-1.log","a");                fprintf(pfile,"mainline staying\n");                fclose(pfile);                sleep(1);        }}
Does the Linux system work properly after the extreme operation?

Redhat is capable of working, except that the corresponding queue operation is not properly stored in the case where all input queues need to be queued. In the event that the memory response is too late, the-bash process puts the operation into the queue, waiting for the command to be sent to the system for execution. The incoming failure waits for the next attempt, and after several attempts, there may be a situation where the resource cannot be used. So it can be said that the operation may be lost. ( non-ANSI keys on the keyboard, such as the arrow keys, BACKSPACE, etc. will not display properly )

Linux Guard Service-Daemon splits child process again

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.