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