Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I tried using the "timelimit" program in the package of the same name in Ubuntu. It originally comes from the netpipes packages, but was packaged separately in Ubuntu. Turns out this program does not work very well. It works if the limited process is the exact process timelimit itself forks. If that process forks any others, those others just keep running.
So I'm looking for a program that can do this function and limit an entire process group. For this all I need is wall clock time limiting. If such a program has to create a whole PTY session much like script does, and kills everything using that PTY, that should be fine, although I think something doing a setsid() should be sufficient.
FYI, just starting up another process that waits till the time end and kills the processes is not safe, since the processes to be limited may just exit early on their own, and something else may later run under recycled process IDs or process group IDs. This absolutely needs to be something that handles things correctly, such as exiting if the managed process group exits.
Anyone heard of such a thing that really works well? I don't want to be re-inventing it if it already exists.
Package: timeoutd
State: not installed
Version: 1.5-10.1ubuntu1
Priority: extra
Section: universe/admin
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Uncompressed Size: 123k
Depends: libc6 (>= 2.7), libx11-6, libxext6, libxss1
Conflicts: suidmanager (< 0.50)
Description: Flexible user timeout daemon with X11 support
timeoutd enforces the time restrictions specified for each or all users.
timeoutd scans /var/run/utmp every minute and checks /etc/timeouts for an entry
which matches a restricted user, based on:
* The current day and time
* The tty that the user is currently logged in on
* The user's login ID
* Any primary or secondary groups the user is in
timeoutd can restrict local users, X11-users and users via telnet/SSH for a
maximum of their session, max. day, idle or no login at all.
timeoutd is also able to restrict users running X.
Sounds like it would be great for limiting kids usage. If only it had a means to test for homework completion
But for my case, I'd doing stuff like a cron job running a script that runs a sequence of rsync updates. Those runs of rsync could last for a long time if there is a lot of data changes. I want to limit them to (for example) 4 hours total. It's that specific cron job that I want to limit. Separate cron jobs possibly running in parallel would have their own timelimits (not necessarily the same time frames). And this also needs to work even when I run the script manually. Limiting a whole user won't work for this, either, since most run as root.
I suspect I have to write my own tool. I'll probably calling setsid() in the forked child before it does execve() to run the specified command, and doing the kill sequence on the whole session (e.g. the session leader process ID negated). Unless some program therein starts its own setsid() session, that should work (my script won't, and as far as I know, rsync doesn't).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.