App-RunStopRun
view release on metacpan or search on metacpan
bin/run-stop-run view on Meta::CPAN
=head1 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.
=head1 OPTIONS
=over 4
=item B<-v>, B<--verbose>
Be verbose.
=item B<-n>, B<--dry-run>
Don't send any signals, just print the command (if given), or list the
PIDs/PGIDs it would affect.
=item B<-l>, B<--limit> I<PERCENT>
The percent of time to run. The default value is 50.0; possible values are
1..99. Specify this with only one of B<--run> or B<--stop>. The other will be
derived.
=item B<-r>, B<--run> I<SECONDS>
The number of seconds to run. The default value is 1.0. Specify this with only
one of B<--limit> or B<--stop>. The other will be derived.
=item B<-s>, B<--stop> I<SECONDS>
The number of seconds to stop. Specify this with only one of B<--limit> or
B<--run>. The other will be derived.
=item B<-p>, B<--pid> I<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.
=item B<-g>, B<--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.
=item B<-G>, B<--no-group>, B<--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 B<pv>). In this case, you will also have to
disable pseudo-terminal allocation, as that results in a call to C<setsid()>,
which creates a new process group.
=item B<-c>, B<--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.
=item B<-T>, B<--no-tty>, B<--notty>
Disable pseudo-terminal allocation.
=item B<-t>, B<--tty>
Force pseudo-terminal allocation. Specifying this more than once will force
allocation even if there is no attached terminal.
=item B<-V>, B<--version>
Display the version.
=item B<-h>, B<--help>
Display the help message.
=item B<-H>, B<--man>
Display this documentation.
=back
=head1 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.
=head1 SEE ALSO
L<https://github.com/opsengine/cpulimit>
L<https://en.wikipedia.org/wiki/Cgroups>
L<https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html>
L<bash(1)/ulimit>
L<nice(1)>, L<renice(8)>
=head1 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.
=head1 AUTHOR
gray, <gray at cpan.org>
=cut
( run in 2.767 seconds using v1.01-cache-2.11-cpan-d8267643d1d )