Skip to content
Snippets Groups Projects
create.pl 5.23 KiB
#!/usr/bin/perl -w
use strict;
$|++;

$ENV{PATH}="/bin:/usr/bin";
$ENV{ENV}="";
$ENV{BASH_ENV}="";
use POSIX ":sys_wait_h";

use diagnostics;
use Getopt::Long;

use vars qw(
	    $MAX_THREADS
	    $SCRIPT_NAME
	    );

# Don't try to run more than this many threads concurrently.
$MAX_THREADS = 16;

$SCRIPT_NAME = "create.pl";

# Initialize variables
my $silent = 0;
my $use_mcreate = 1; # should we use mcreate or open?
my $num_files = 5;   # number of files to create
my $iterations = 1;
my $num_threads = 1;
my $mountpt;
my $num_mounts = -1;

# Get options from the command line.
GetOptions("silent!" => \$silent,
           "use_mcreate=i" => \$use_mcreate,
           "num_files=i" => \$num_files,
	   "mountpt=s" => \$mountpt,
	   "num_mounts=i" => \$num_mounts,
	   "iterations=i" => \$iterations,
	   "num_threads=i" => \$num_threads,
	   ) || die &usage;

# Check for mandatory args.
if (!$mountpt || 
    !$num_mounts) {
    die &usage;
}

if ($num_threads > $MAX_THREADS) {
    print "\nMAX_THREADS is currently set to $MAX_THREADS.\n\n";
    print "You will have to change this in the source\n";
    print "if you really want to run with $num_threads threads.\n\n";
    exit 1;
}

# Initialize rand() function.
srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);

#########################################################################
### MAIN

for (my $i=1; $i<=$num_threads; $i++) {
    my $status = &fork_and_create($i);
    last if ($status != 0);
}

# Wait for all our threads to finish.
my $child = 0;
do {
    $child = waitpid(-1, WNOHANG);
} until $child > 0;