added correct commands and removed duplicate stress functions

This commit is contained in:
2026-05-22 20:16:30 +03:00
parent d80cb3e1a7
commit d4e700f980
5 changed files with 48 additions and 112 deletions
-1
View File
@@ -1,3 +1,2 @@
Maximum_limit_stress_test/count_file.txt
creation_time_experiment/creation_time_results.txt
thread_recursive_scaling/runs/
-78
View File
@@ -1,78 +0,0 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <string.h>
#define DEFAULT_NUM_LEN 512
char *itoa(long num, char *strnum, size_t size){
int isNegative = 0;
if(num == 0){
strnum[0] = '0';
strnum[1] = '\0';
return strnum;
}
if(num < 0){
isNegative = 1;
num = -num;
}
int counter = 0;
while(num > 0 && counter <(int)(size-1)){
strnum[counter] = num % 10 + '0';
num /= 10;
counter ++;
}
if(isNegative){
strnum[counter] = '-';
counter++;
}
strnum[counter] = '\0';
for(int i=0; i<counter/2; i++){
char temp = strnum[i];
strnum[i] = strnum[counter-1-i];
strnum[counter-1-i] = temp;
}
return strnum;
}
int main(){
int fd = open("count_file.txt",O_CREAT | O_WRONLY | O_TRUNC,0600);
long count = 0;
char intstr[DEFAULT_NUM_LEN];
while(1){
pid_t pid = fork();
if(pid < 0){
perror("fork");
break;
}
if(pid == 0){
sleep(100);
return 0;
}
count++;
lseek(fd,0,SEEK_SET);
memset(intstr,0,sizeof(intstr));
itoa(count,intstr,DEFAULT_NUM_LEN);
write(fd,intstr,strlen(intstr));
}
close(fd);
printf("Max forks: %ld\n",count);
while(wait(NULL) > 0);
return 0;
}
+30 -4
View File
@@ -19,16 +19,42 @@ bash creation_time_experiment/bash_test_iter.sh
bash thread_recursive_scaling/run_thread_recursive.sh
```
Enable the dangerous stress tests (timeboxed):
Enable the dangerous stress test (timeboxed):
```sh
ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 MAX_LIMIT_SECONDS=5 bash run_all_experiments.sh
ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 bash run_all_experiments.sh
```
## Key Commands for lifting linux kernel restrictions on alpine linux for threads & processes:
```
# Lift shell nproc limit
ulimit -u unlimited
# Raise kernel PID/thread caps (temporary until reboot)
sysctl -w kernel.pid_max=131072
sysctl -w kernel.threads-max=131072
# cgroup v2 setup (Alpine Linux)
mkdir -p /sys/fs/cgroup/test
echo max > /sys/fs/cgroup/test/pids.max
echo $$ > /sys/fs/cgroup/test/cgroup.procs
```
## Clean-up commands run after tests:
```
# Cleanup to make it non-persistent (move out, then delete)
echo $$ > /sys/fs/cgroup/cgroup.procs
rmdir /sys/fs/cgroup/test
```
## Potential dangers
- The fork bomb and max-limit stress tests can freeze your machine or make it
unresponsive by exhausting processes/threads.
- The fork bomb can freeze your machine or make it unresponsive by exhausting
processes/threads.
- You may need elevated limits (ulimit or sysctl) to run high-stress tests.
- Running heavy tests on shared systems or laptops can disrupt other users and
risk data loss if the system becomes unstable.
-19
View File
@@ -142,12 +142,6 @@ compile_fork_bomb() {
"$ROOT_DIR/fork_bomb/fork_bomb.c"
}
compile_max_limit() {
log "Compiling stress"
gcc -O2 -o "$ROOT_DIR/Maximum_limit_stress_test/stress" \
"$ROOT_DIR/Maximum_limit_stress_test/stress.c"
}
compile_thread_stress() {
log "Compiling thread_stress"
gcc -O2 -pthread -o "$ROOT_DIR/thread_stress_test/thread_stress" \
@@ -156,13 +150,11 @@ compile_thread_stress() {
compile_creation_time
compile_fork_bomb
compile_max_limit
compile_thread_stress
# Defaults (override by env vars)
ALLOW_DANGEROUS=${ALLOW_DANGEROUS:-0}
FORK_BOMB_SECONDS=${FORK_BOMB_SECONDS:-5}
MAX_LIMIT_SECONDS=${MAX_LIMIT_SECONDS:-5}
CREATION_TIME_ITERS=${CREATION_TIME_ITERS:-"100 1000 10000"}
CREATION_TIME_SECONDS=${CREATION_TIME_SECONDS:-60}
@@ -186,17 +178,6 @@ else
echo "timestamp,elapsed_s,load1,load5,load15,mem_total_kb,mem_available_kb,mem_used_kb,proc_count,thread_count_total,pid,cpu_pct,rss_kb,vsz_kb,stack_kb,heap_kb,proc_threads" > "$OUT_DIR/fork_bomb.csv"
fi
if [ "$ALLOW_DANGEROUS" -eq 1 ]; then
run_with_sampling \
"max_limit_stress" \
"cd '$ROOT_DIR/Maximum_limit_stress_test' && ./stress" \
"$OUT_DIR/max_limit_stress.csv" \
"$MAX_LIMIT_SECONDS"
else
log "Skipping max_limit_stress (set ALLOW_DANGEROUS=1 to run)"
echo "timestamp,elapsed_s,load1,load5,load15,mem_total_kb,mem_available_kb,mem_used_kb,proc_count,thread_count_total,pid,cpu_pct,rss_kb,vsz_kb,stack_kb,heap_kb,proc_threads" > "$OUT_DIR/max_limit_stress.csv"
fi
run_with_sampling \
"thread_recursive_scaling" \
"cd '$ROOT_DIR/thread_recursive_scaling' && ./run_thread_recursive.sh" \
+18 -10
View File
@@ -29,9 +29,6 @@ to understand how the operating system balances efficiency and isolation.
- [x] Thread Recursive Scaling:
Similar recursive creation using threads to compare scalability and resource usage against
fork().
- [x] Maximum Limit Stress Test:
Continuously creates processes or threads until the system refuses further creation,
revealing OS-enforced limits on concurrency.
- [ ] Memory and Stability Observation(removed max forks with ulimit -u 20000):
Monitors system memory usage and system responsiveness during heavy process and
thread creation.
@@ -59,23 +56,34 @@ Citations will include:
ulimit -u unlimited
# Raise kernel PID/thread caps (temporary until reboot)
sudo sysctl -w kernel.pid_max=131072
sudo sysctl -w kernel.threads-max=131072
sysctl -w kernel.pid_max=131072
sysctl -w kernel.threads-max=131072
# Lift cgroup v2 pids limit (temporary until reboot)
sudo sh -c 'echo max > /sys/fs/cgroup/pids.max'
# cgroup v2 setup (Alpine Linux)
mkdir -p /sys/fs/cgroup/test
echo max > /sys/fs/cgroup/test/pids.max
echo $$ > /sys/fs/cgroup/test/cgroup.procs
```
## Clean-up commands run after tests:
```
# Cleanup to make it non-persistent (move out, then delete)
echo $$ > /sys/fs/cgroup/cgroup.procs
rmdir /sys/fs/cgroup/test
```
## Crash/Stress Behavior (Runner Env Vars)
The runner script uses the following environment variables to control risky experiments:
- `ALLOW_DANGEROUS=1` to enable `fork_bomb` and `max_limit_stress` (default: 0).
- `ALLOW_DANGEROUS=1` to enable `fork_bomb` (default: 0).
- `FORK_BOMB_SECONDS=<seconds>` to timebox `fork_bomb` runtime.
- `MAX_LIMIT_SECONDS=<seconds>` to timebox `max_limit_stress` runtime.
Example:
```sh
ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 MAX_LIMIT_SECONDS=5 bash run_all_experiments.sh
ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 bash run_all_experiments.sh
```