Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Jan 2018 11:57:41 +0000
From:      Frank Leonhardt <freebsd-doc@fjl.co.uk>
To:        Freebsd Questions <freebsd-questions@freebsd.org>
Subject:   Re: Limit resources for a given program
Message-ID:  <a3fcaed4b8af7b3cd9a377bf9ab0ab46@roundcube.fjl.org.uk>
In-Reply-To: <CA%2Bg%2BBviCY1CtPQeLX=QrY4Ky9Y06q1mtTY1hNvbi4B7s5xRNGw@mail.gmail.com>
References:  <wu78tcpgmke.fsf@banyan.cs.ait.ac.th> <2014529083ae48e21732fa60a4062356@roundcube.fjl.org.uk> <CA%2Bg%2BBviCY1CtPQeLX=QrY4Ky9Y06q1mtTY1hNvbi4B7s5xRNGw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2018-01-26 05:19, Olivier Nicole wrote:
> Frank,
> 
> On Thu, Jan 25, 2018 at 5:47 PM, Frank Leonhardt <frank2@fjl.co.uk> 
> wrote:
>> On 2018-01-23 05:40, Olivier wrote:
>>> 
>>> Is there a way, in FreeBSD, to limit the clocktime for a given 
>>> command?
>>> 
>>> I use LibreOffice to automatically convert many types of documents to
>>> PDF. When it is an HTML document with external links, it will run
>>> indefinitely, trying to access the external resources. It will not 
>>> use
>>> much CPU but mostly sits idled, so limits(8) -t is not the solution, 
>>> nor
>>> is rctl(8) that needs a process ID (but I only have the command name) 
>>> or
>>> a user ID (but I don't want to limit a user, just that program).
>> 
>> 
>> I'm a bit confused about what your problem is? What exactly do you 
>> mean by
>> "clocktime" - do you mean wall time (i.e. time elapsed)? You say it's 
>> not
>> using a lot of resource, so what's the problem?
>> 
>> Or do you just want to kill it when it gets stuck?
> 
> Yes, I mean time elapsed. Even if it does not takes much resources,
> when such process got launched again and again, it ends up having some
> cost.
> 
> So I want it to be killed when it gets stuck.

Steve's plan using rctl posted at about same time is probably the safest 
way. The classic method is to use the $! shell variable, which gives the 
PID of the background process just started. So something like this 
should also work on all platforms - rctl &c is new.

libreoffice whatever & sleep 60 ; kill $!

Alternatively (if you want your prompt back):

libreoffice whatever & echo kill $! | at +5 minutes

The drawback with using $! and suchlike these days is that the pid could 
be reused in a relatively short space of time, especially if you're 
randomising PIDs for security.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a3fcaed4b8af7b3cd9a377bf9ab0ab46>