[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The memory occupied by bash has been increasing due to the fork bomb

From: wang yuhang
Subject: The memory occupied by bash has been increasing due to the fork bomb
Date: Fri, 10 Mar 2023 17:28:05 +0800

Hello !

I am now doing a test on the fork bomb with the command `:(){:|:&};:` and 
set `ulimit - c 1000`. And everything was well in bash-5.0, but there was a 
problem in bash-5.1. 

The main performance is that the system memory has been rising, and then the 
kernel appears the oom, I found that the memory increase may be caused by 
the following reasons:

First, systemd will send a sigterm to bash, but in bash-5.1, the bash process 
will not be killed. this was caused by a change in bash 5.1. The modified 
change information is as follows
sss. Fix a bug where receiving SIGTERM from a different process while readline 
was active could cause the shell to terminate

Second, When bash fork is a child process, it always creates a memory to 
manage the job, even if the maximum number set by the ulimit command is reached
int stop_pipeline(async, deferred)
int async;
COMMAND *deferred;
    ... ...
    if (js.jobslots == 0) {
        ... ...
        jobs = (JOB **)xmalloc(js.j_jobslots * sizeof(JOB 
        ... ...
    ... ...
    if (i == js.jobslots) {
        ... ...
        jobs = (JOB **)xrealloc(js.j_jobslots * sizeof(JOB 
        ... ...


After my own positioning, the above is probably the reason for the memory 
increase. Could you tell me how to avoid or optimize memory increase ?

thanks ??

reply via email to

[Prev in Thread] Current Thread [Next in Thread]