Skip to content

Commit

Permalink
Limit the memory usage via ulimit
Browse files Browse the repository at this point in the history
Use the `ulimit -v` to limit the memory to overcome memory leakage issue

Signed-off-by: Chun-Yu Lee (Mat) <matlinuxer2@gmail.com>
  • Loading branch information
matlinuxer2 committed Jul 23, 2024
1 parent 119498a commit 04a6d39
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stl-thumbnailer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ fi
INPUT_FILE=$1
OUTPUT_FILE=$2
SIZE=$3
MEM_LIMIT_KiB=$(( 300 * 1024 )) # Limit the memory usage to 300 MiB

TEMP="$(mktemp --directory --tmpdir tumbler-stl-XXXXXXX)"
# Use a sub shell to enclose the commands in case it aborts and skip the last cleanup action
# Sub shell BEG
(
ulimit -v $MEM_LIMIT_KiB
cp "$INPUT_FILE" "$TEMP/source.stl"

echo "import(\"source.stl\", convexity=10);" >"$TEMP/thumbnail.scad"
Expand Down

0 comments on commit 04a6d39

Please sign in to comment.