fork download
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use File::Path;
  5. use IO::File;
  6.  
  7. sub diskstat {
  8. system("grep sda5 < /proc/diskstats") # Linux ONLY
  9. }
  10.  
  11. sub f_a {
  12. my $fh = IO::File->new( &genfn(),'>') || die( $!);
  13. $fh->autoflush( 0);
  14. foreach ( 0 .. 5){
  15. $fh->print('h') foreach 0 .. 99999;
  16. sleep( 6);
  17. }
  18. $fh->close;
  19. }
  20.  
  21. sub f_b {
  22. my $fh = IO::File->new( &genfn(),'>') || die( $!);
  23. $fh->autoflush( 1);
  24. foreach ( 0 .. 5){
  25. $fh->print('h') foreach 0 .. 99999;
  26. sleep( 6);
  27. }
  28. $fh->close;
  29. }
  30.  
  31. sub f_c {
  32. my $fn = &genfn();
  33. foreach ( 0 .. 5) {
  34. foreach ( 0 .. 99999) {
  35. my $fh = IO::File->new( $fn,'>>') || die( $!);
  36. $fh->print('h');
  37. $fh->close;
  38. }
  39. sleep( 6);
  40. }
  41. }
  42.  
  43. {
  44. my @conf_a = (
  45. [\&f_a,'f_a'],
  46. [\&f_b,'f_b'],
  47. [\&f_c,'f_c'],
  48. );
  49. foreach my $dir ( map { $_->[1] } @conf_a){
  50. rmtree( $dir);
  51. mkpath( $dir);
  52. }
  53. my $sno = 0;
  54. &diskstat();
  55. foreach my $item ( @conf_a){
  56. local *genfn = sub { $item->[1] . '/' . $sno++ };
  57. $item->[0]->();
  58. sleep( 6);
  59. &diskstat();
  60. }
  61. }
  62.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty