Resource limits – Part II (hard limits)
anomit | June 26, 2009So much for late night coding. Yesterday I missed out on a very important part about setting the hard limits on resources. But you need to have a superuser process to achieve this. Referring to the code of exec.c in the previous post, put in this after line no. 18.
limit.rlim_max =1;
This is actually the hard limit and as the man page says, it acts as a ceiling for the soft limit i.e. rlim_cur. The advantage being that if the process exceeds the limit and yet continues running such as by handling the SIGXCPU signal in the previous example, this time a SIGKILL will be issued which would force it to terminate.
Now compile exec.c as usual and run it as root. You won’t see any output as we set the hard limit equal to the soft limit.
- Soft limit reached, SIGXCPU sent
- Process tries to handle it
- At the same time the hard limit i.e. the ceiling for soft limit is reached too. So a SIGKILL is sent and the process terminates before any output.






