runlim
Limit resource consumption of a program
TLDR
Print the time and memory usage of a command
Log statistics to a file instead of stdout
Limit time to an upper bound (in seconds)
Limit real-time to an upper bound (in seconds)
Limit space to an upper bound (in MB)
SYNOPSIS
runlim [options] command [arguments]
PARAMETERS
-t
Set CPU time limit to
-f
Set file size limit to
-m
Set memory usage limit to
-p
Set CPU usage percentage limit to
-o
Redirect standard output to
-e
Redirect standard error to
-i
Redirect standard input from
DESCRIPTION
The runlim command allows you to execute another command with specified limits on resource usage, such as CPU time, memory usage, and file size. This is useful for testing the resource consumption of programs, preventing programs from consuming excessive resources and potentially crashing the system or for running untrusted code in a controlled environment.
runlim sets resource limits using the setrlimit system call before executing the given command. If the command exceeds any of the specified limits, it will be terminated and runlim will print an error message to standard error. If no explicit limit is specified, it usually uses the current shell limit. It is important to note that the limits set by runlim only apply to the command it executes, and not to the shell itself.
CAVEATS
The accuracy of resource limits, especially CPU time, may be affected by system load and scheduling. Some programs might be able to circumvent certain limits. It's also essential to understand the implications of redirecting standard input/output/error, as it can affect the behavior of the executed command.
EXIT STATUS
runlim returns the exit status of the command it executed. If the command is terminated due to exceeding a resource limit, runlim returns a non-zero exit status, indicating the failure. A successful termination of the command results in runlim returning the command's exit status.
HISTORY
The runlim command has been available in some Linux distributions and Unix-like systems for a considerable amount of time. Its design is rooted in the need to control resource consumption, particularly when dealing with potentially untrusted or resource-intensive processes. Over time, implementations may have varied slightly, but the core functionality of limiting resource usage remains consistent.