Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- my $ncpu = shift or die "usage: $0 NUMCORES [--sleep]\n";
- my $xarg = shift;
- my $afflist = "0-".($ncpu-1);
- if($xarg eq '--child') {
- hog();
- }
- else {
- # parent process -> set affinity (inherited by all children)
- system("taskset -p -c $afflist $$");
- for(1..$ncpu) {
- # note: the exec() is important!
- # calling hog() directly would not trigger
- # the problem
- exec($0, -1, "--child") if fork() == 0;
- select(undef,undef,undef,0.01) if $xarg eq '--sleep';
- }
- for(;;) { sleep(10); }
- }
- # exec'd child: waste CPU
- sub hog {
- for(;;) {}
- }
Add Comment
Please, Sign In to add comment