]> www.opopop.net Git - reminder/blob - running_a_process_with_limited_ressources.mdwn
(no commit message)
[reminder] / running_a_process_with_limited_ressources.mdwn
1 Suppose you run a real time critical application receiving formatted
2 messages, which are decoded by some library.
3
4 In addition, the sent messages can be wrongly formatted, which can
5 throw your decoding library in an infinite loop or lead to allocating
6 too much memory. In short the library in question is badly written and
7 so very unsafe.
8
9 Curing that at the core is out of the equation, as the library is too
10 complex to be maintained with the limited manpower available. Yes,
11 it seems odd, but that's how reality is sometimes...
12
13 To avoid the application going berserk and ultimately crashing in the
14 case of bad input, I wanted to run the message decoding step as a
15 child process, but with limited CPU and memory ressources. If these
16 ressources are overshot, the parent process is signaled and the
17 decoded message is dropped.
18
19 You would believe that Unix like systems have nice facilities to do
20 that out of the box? The answer is not a sounding "yes". The case for
21 memory management in Linux is especially vexing, as Linux seems happy
22 by default to let every process allocate as much as it wants.
23
24 Below is a little program I have devised to test limits on:
25
26 1. the "brk" memory (-b argument)
27 1. the malloced memory (-m argument)
28 1. the CPU time (-c argument)
29
30 Notice how every case has it's own strategy to set and enforce the
31 limit. 
32
33 Link to the program: [[limit.tgz]]