Guest User

Untitled

a guest
Apr 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.60 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. my $ncpu    = shift or die "usage: $0 NUMCORES [--sleep]\n";
  5. my $xarg    = shift;
  6. my $afflist = "0-".($ncpu-1);
  7.  
  8. if($xarg eq '--child') {
  9.     hog();
  10. }
  11. else {
  12.     # parent process -> set affinity (inherited by all children)
  13.     system("taskset -p -c $afflist $$");
  14.    
  15.     for(1..$ncpu) {
  16.         # note: the exec() is important!
  17.         # calling hog() directly would not trigger
  18.         # the problem
  19.         exec($0, -1, "--child") if fork() == 0;
  20.        
  21.         select(undef,undef,undef,0.01) if $xarg eq '--sleep';
  22.        
  23.     }
  24.     for(;;) { sleep(10); }
  25. }
  26.  
  27.  
  28. # exec'd child: waste CPU
  29. sub hog {
  30.     for(;;) {}
  31. }
Add Comment
Please, Sign In to add comment