0

I have a situation where a process that hangs under certain circumstances or runs for too long should be killed. Also I don't want the process to take 100% of the CPU time. I am thinking that I should combine cpulimit and timeout.

I can get each command to work separately but not together:

cpulimit -l 20 -- /usr/lib/libreoffice/program/soffice.bin --headless --convert-to pdf broken.docx

timeout -k 6 -s 15 6s /usr/lib/libreoffice/program/soffice.bin --headless --convert-to pdf broken.docx

I would like to do something like:

cpulimit -l 20 -- | timeout -k 6 -s 15 6s /usr/lib/libreoffice/program/soffice.bin --headless --convert-to pdf broken.docx

2 Answers 2

0

You may try to run the timeout command as argument of the cpulimit:

cpulimit -l 20 -- timeout -k 6 -s 15 6s /usr/lib/libreoffice/program/soffice.bin --headless --convert-to pdf broken.docx

Note that this is exactly like your last example but without the pipe | (the pipe chains the output of the first process with the input of the second that is not what you want here).

2
  • Problem with this solution is that only the timeoutcommand has any effect. cpulimit is ignored.
    – Cudos
    Jan 10, 2019 at 9:47
  • swapping timeout and cpulimit may fix it?
    – cmaglie
    Jan 11, 2019 at 13:21
0

I ended up using nice with timeout instead. One problem with cpulimit and timeout combo was that soffice.binspawned several processes and the parent process somehow wasn't affected.

That solved my problem.

Also nice give the process the possibility to use 100% of the CPU if no other processes are running instead of a hard cap on the resources.

nice timeout -k 5 6s /usr/lib/libreoffice/program/soffice.bin --headless --convert-to pdf broken.docx

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .