LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Runaway train (https://www.linuxquestions.org/questions/programming-9/runaway-train-4175614387/)

danielbmartin 09-23-2017 03:41 PM

Runaway train
 
I might be testing an unfinished program. A bug causes the program to write six bazillion lines to an output file. Is there a way to prevent this? A way for Linux Mint to detect a runaway train?

This has not happened (honest!) but the possibility is worrisome.

Daniel B. Martin

ntubski 09-23-2017 04:39 PM

Code:

~$ help ulimit
ulimit: ulimit [-SHabcdefiklmnpqrstuvxPT] [limit]
[...]
      -f        the maximum size of files written by the shell and its children
~$ ulimit -f 10
~$ ulimit -a
[...]
file size              (blocks, -f) 10
~$ yes > foo.txt
File size limit exceeded
~$ ls -sh foo.txt
12K foo.txt

This doesn't seem to defend against writing six bazillion files of 1 line each though (there is ulimit -n for max number of open files, but that's not a barrier if the program closes each file quickly).

It might also be worth limiting virtual memory (ulimit -v) to somewhere around the size of your physical RAM to prevent a single program with a major memory leak from filling up your swap space (this tends to slow down the entire system as it writes to swap).

tofino_surfer 09-25-2017 03:17 PM

Quote:

t might also be worth limiting virtual memory (ulimit -v) to somewhere around the size of your physical RAM to prevent a single program with a major memory leak from filling up your swap space (this tends to slow down the entire system as it writes to swap).
First of all the OP isn't discussing memory leaks but rather a program which goes into endless loops generating unlimited amounts of data.

There is a much better way of handling runaway programs and files. You need to create a separate partition for the output of such un-trusted programs. A partition of modest size such as 100 - 500 MB would fill up fast and then generate an error code if writes were attempted to a full file system. You would need to check the error code after each write operation to this small partition. Filling up a small separate partition wouldn't affect your main file system.

This separate partition technique is traditionally used by developers to keep an un-trusted program from filling up your main file system.

ntubski 09-25-2017 03:43 PM

quota and setquota may also be of interest.


All times are GMT -5. The time now is 10:11 AM.