Many mechanical and electronic systems run part-time — air conditioning, for instance. The dutycycle is the fraction of time the system is on, typically expressed as a percentage, from 0 percent (always off) to 100 percent (always on). A related metric is the length of an on-off cycle, the cycle time. The dutycycle program in Listing 1 lets you control both. At the default setting of 50 percent dutycycle and a 100 millisecond cycle time (i.e., on for 50 millisecond, off for 50 milliseconds), the CPU temperature rise during kernel builds is cut almost in half.
The basic idea of dutycycle is to fork off the controlled program, sleep for a bit, pause the controlled program, sleep a bit more, then resume it, repeating until the controlled program exits. The POSIX standard signals STOP and CONT (continue), respectively pause and resume a process. That is OS independent enough for me and requires no experimental kernel code. This code has only been tested on Linux, but should work on most Unix work-alikes and other sufficiently POSIX-compliant operating systems. (POSIX is a bunch of standards, not just one; how many parts and how well implemented they are varies.)


