#!/usr/bin/perl use Fcntl; my $fifo = "/tmp/fixfreq"; system "mkfifo", $fifo; chmod 0600, $fifo; sysopen( READ_PIDS, $fifo, O_NONBLOCK|O_RDONLY) or die "Can't open modem: $!\n"; END { set( 0 ); close READ_PIDS; unlink $fifo; } sub bye { exit; } $SIG{TERM} = \&bye; $SIG{INT} = \&bye; my $now_is = ""; sub set { my $num = shift; my $set_to = $num ? "performance" : "ondemand"; return if $now_is eq $set_to; $now_is = $set_to; foreach my $gov ( glob "/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor" ) { open GOV, ">", $gov; print GOV $set_to; close GOV; } } my %pids; while ( 1 ) { foreach my $pid ( keys %pids ) { unless ( -d "/proc/".$pid ) { delete $pids{ $pid }; } } while ( my $pid = ) { chomp $pid; if ( -d "/proc/$pid" ) { $pids{ $pid } = 1; } } set( keys %pids ); sleep 1; }