It's a repo to store everything related to this course.
We test all scenarios for flush function in C language.
We can see in the outputs files different cases and different outputs.
The program accepts several parameters to enable or disable specific options:
-d: Default scenario - Usesfflushto ensure immediate output for bothSTDOUTandSTDERR.-n: Newline scenario - Adds\nto the output, utilizing line-buffering forSTDOUTand immediate output forSTDERR.-s: Without fflush - Omitsfflush, soSTDOUTmay delay until the program exits, whileSTDERRappears immediately.-r: Redirect output - Demonstrates behavior when output is redirected to a file without\norfflush, causing potential delay inSTDOUTwhileSTDERRappears immediately.
To compile and run each scenario, execute the following commands:
# Compile the program
gcc -o program main.c
# Run default scenario with fflush
./program -d
# Run scenario with newline (\n) addition
./program -n
# Run scenario without fflush
./program -s
# Run scenario with redirected output
./program -r
# Run all scenarios with the script
./run_experiments.sh- Original program:
Here we used the the original code, and we can see that "STDOUT" and "STDERR" appear immediately due to explicit fflush. - With
\nadded:
We see that both "STDOUT\n" and "STDERR\n" appear immediately due to line-buffering. - Without fflush:
"STDOUT" delay and wait until the program ends, "STDERR" appears immediately. - Redirecting output to a file without "/n" or flush:
"STDOUT" may delay, "STDERR" apears immediately.
This program demonstrates how memory allocation, reading, and writing operations impact system behavior. By simulating controlled memory access patterns, the program explores scenarios of paging, memory consumption, and system performance under varying conditions.
The program is parameterized to allow flexible configuration of memory size, access modes, pause frequency, and duration. It also enables monitoring of system behavior using external tools like free.
- Compilation
gcc main.c- You can check all configurations using:
./a.out -h- Or use the following table:
| Option | Description | Default value |
|---|---|---|
| -m, --memory_size | Memory size to allocate (MB) | 128 |
| -a, --access_mode | Access mode: read or write |
read |
| -p, --pause_steps | Number of steps (4 KB blocks) befure pausing | 1000 |
| -d, --pause_time | Pause duration in milliseconds | 100 |
| -h, --help | Show help message and exit | |
- Default
./a.out- Write mode
./a.out -m 256 -a write -p 500 -d 50- Stress test
./a.out -m 5120 -a write -p 10000 -d 0- Small allocaton with fast pauses
./a.out -m 500 -a read -p 100 -d 10- Help Message
./a.out -hUsing free -m during the pauses to observe total system memory usage in MB.
- Read vs Write
- Read Mode : Memory usage remains stable.
- Write Mode : Physical memory allocation grows as pages are dirtied. When exceeding the maximum system will crash.
- Continuous Write with no pauses:
- Causes rapid memory consumption and high system load.
This module demonstrates generating fractals in C and saving the results in PGM format. I applied three fractals as I found:
- Julia
- Sierpinski Carpet
- Mandelbrot Set
I reused image.c to manage the image buffers and write the result to .pgm
-
The main entry point is
main.cthat contains the fractal generation codes. -
Compilation:
-
Option A: Using a Makefile (recommended)
make make clean
After
make, you should have two executables:fractal(production)test_fractal(test binary)
-
Option B: Manual Commands
Production build:gcc -c image.c -o image.o gcc -c fractal.c -o fractal.o -lm gcc -c main.c -o main.o -lm gcc image.o fractal.o main.o -o fractal -lm
Test build:
gcc -c image.c -o image.o gcc -c fractal.c -o fractal.o -lm gcc -c test_fractal.c -o test_fractal.o gcc image.o fractal.o test_fractal.o -o test_fractal -lm
-
-
Running: We can pass two params:
- Fractal type:
julia,sierpinskiormandelbrot. - Output filename default
fractal_output.pgm
./fractal
./fractal sierpinski carpet.pgm
./fractal mandelbrot mandelbrot.pgm- Viewing PGM:
convert fractal_output.pgm fractal_output.png