int o_abort = 0;
int o_quiet = 0;
+void usage(char *name)
+{
+ fprintf(stderr, "usage: %s [opts] <dirname> <seconds> <threads>\n",
+ name);
+ fprintf(stderr, " -q quiet\n");
+ fprintf(stderr, " -a abort other children on first err\n");
+ exit(1);
+}
+
+
struct kid_list_t {
pid_t kid;
struct kid_list_t *next;
}
}
+static int usr1_received;
+void usr1_handler(int unused)
+{
+ usr1_received = 1;
+ kill_kids();
+}
+
int wait_for_threads(int live_threads)
{
int rc = 0;
-
+
while (live_threads > 0) {
int status;
pid_t ret;
-
+
ret = waitpid(0, &status, 0);
if (ret == 0) {
continue;
}
-
+
if (ret < 0) {
fprintf(stderr, "%s: error: wait - %s\n",
cmdname, strerror(errno));
* always returns 1 (OK). See wait(2).
*/
int err = WEXITSTATUS(status);
- if (err || WIFSIGNALED(status))
+ if (err)
fprintf(stderr,
"%s: error: PID %d had rc=%d\n",
cmdname, ret, err);
void print_err(char *op, char *filename, struct timeval *time, int err)
{
fprintf(stderr, "%s: %d.%.06d error: %s(%s): %s\n",
- cmdname, (int)(time->tv_sec), (int)(time->tv_usec), op,
+ cmdname, (int)(time->tv_sec), (int)(time->tv_usec), op,
filename, strerror(errno));
}
int fd, rc = 0, rand, maxrand, len;
long nfiles = 0, nbytes = 0;
- if (!o_quiet)
+ if (!o_quiet)
printf("%s: running thread #%d\n", cmdname, thread);
-
+
srandom(thread);
- /* Higher thread numbers will produce bigger random files.
+ /* Higher thread numbers will produce bigger random files.
Thread 1 will produce only 0-len files. */
maxrand = 1; rand = thread;
while (--rand)
gettimeofday(&start, NULL);
while(!rc) {
- gettimeofday(&cur, NULL);
- if (cur.tv_sec > (start.tv_sec + seconds))
+ if (usr1_received)
break;
- sprintf(filename, "%s-%d-%ld", file, thread, nfiles);
+ gettimeofday(&cur, NULL);
+ if (seconds) {
+ if (cur.tv_sec > (start.tv_sec + seconds))
+ break;
+ }
+ sprintf(filename, "%s-%d-%ld", file, thread, nfiles);
+
fd = open(filename, O_RDWR | O_CREAT, 0666);
if (fd < 0) {
print_err("open", filename, &cur, errno);
rc = errno;
break;
}
-
- sprintf(buf, "%s %010ld %.19s.%012d\n", cmdname,
+
+ sprintf(buf, "%s %010ld %.19s.%012d\n", cmdname,
nfiles++, ctime(&cur.tv_sec), (int)cur.tv_usec);
len = strlen(buf);
print_err("write", filename, &cur, errno);
rc = errno;
break;
- }
+ }
nbytes += len;
- }
-
+ }
+
if (close(fd) < 0) {
print_err("close", filename, &cur, errno);
rc = errno;
break;
}
}
-
+
diff = difftime(&cur, &start);
- if (!o_quiet)
- printf("%s: %7ld files, %4ld MB in %.2fs (%7.2f files/s, "
+ if (!o_quiet)
+ printf("%s: %7ld files, %4ld MB in %.2fs (%7.2f files/s, "
"%5.2f MB/s): rc = %d\n",
cmdname, nfiles, nbytes >> 20, diff,
(double)nfiles / diff, (double)nbytes/1024/1024 / diff,
return rc;
}
-void usage(char *name)
-{
- fprintf(stderr,
- "usage: %s [opts] <dirname> <seconds> <threads>\n",
- name);
- fprintf(stderr, " -q quiet\n");
- fprintf(stderr, " -a abort other children on first err\n");
- exit(1);
-}
-
int main(int argc, char *argv[])
{
unsigned long duration;
char *directory;
int i = 1, rc = 0;
- sprintf(cmdname, "%s", argv[0]);
+ sprintf(cmdname, "%s", argv[0]);
while((i < argc) && (argv[i][0] == '-')) {
switch (argv[i][1]) {
exit(2);
}
+ signal(SIGUSR1, usr1_handler);
+
for (i = 1; i <= threads; i++) {
rc = fork();
if (rc < 0) {
}
}
/* parent process */
- if (!o_quiet)
+ if (!o_quiet)
printf("%s will run for %ld minutes\n", cmdname, duration/60);
return (wait_for_threads(threads));
}