NAME

run-stop-run - limit CPU usage of processes

SYNOPSIS

run-stop-run [options] command [arguments]
run-stop-run [options] -p PID,-PGID

DESCRIPTION

This program controls the CPU usage of processes by repeatedly sending SIGSTOP and SIGCONT signals. It can be used to run a command or on the PIDs of already-running processes.

It is useful in the case that you have a long-running CPU-intensive process and want to maintain a thermal limit (think fanless computer). Or you may have a program that uses all cores without providing a means to configure the level of concurrency.

OPTIONS

-v, --verbose

Be verbose.

-n, --dry-run

Don't send any signals, just print the command (if given), or list the PIDs/PGIDs it would affect.

-l, --limit PERCENT

The percent of time to run. The default value is 50.0; possible values are 1..99. Specify this with only one of --run or --stop. The other will be derived.

-r, --run SECONDS

The number of seconds to run. The default value is 1.0. Specify this with only one of --limit or --stop. The other will be derived.

-s, --stop SECONDS

The number of seconds to stop. Specify this with only one of --limit or --run. The other will be derived.

-p, --pid PID,-PGID

A list of PIDs of already-running processes. The list may be comma-separated or the option given multiple times. If the PID is negative, it is interpreted as a process group.

-g, --group

Operate on the entire process group. This is the default when running a command, as it will start a new process group. When operating on a list of PIDs, it will determine the associated process groups and operate on them directly.

-G, --no-group, --nogroup

Don't create a new process group for the command to run. When operating on a list of PIDs, it will not determine associated process groups and operate on them, but it will still operate on any given PGIDs.

Note that creating a new process group causes the command to be run in the background, and some commands refuse to print if they are not the foreground process (ex. newer versions of pv). In this case, you will also have to disable pseudo-terminal allocation, as that results in a call to setsid(), which creates a new process group.

-c, --children

Operate on all descendent processes of the command or PIDs. These are found by scanning the process table and checking the parent process and group of each process. Note that it's not always possible to determine the parentage, since the process might have double-forked and changed it's process group.

-T, --no-tty, --notty

Disable pseudo-terminal allocation.

-t, --tty

Force pseudo-terminal allocation. Specifying this more than once will force allocation even if there is no attached terminal.

-V, --version

Display the version.

-h, --help

Display the help message.

-H, --man

Display this documentation.

KNOWN PROBLEMS

Operating on a PID of a foreground process will likely result in job control messages from the shell indicating the job was stopped when it receives the SIGSTOP signal. Note that the job will be continued in the background after receiving the SIGCONT signal, but no shell messages will be displayed.

It is not always possible to determine if a process is a child process. In that case, you can run the command separately and then run this program against a list of PIDs.

SEE ALSO

https://github.com/opsengine/cpulimit

https://en.wikipedia.org/wiki/Cgroups

https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html

"ulimit" in bash(1)

nice(1), renice(8)

COPYRIGHT AND LICENSE

Copyright (c) 2022 gray <gray at cpan.org>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

gray, <gray at cpan.org>