user/logstress.c
48 lines
1#include "kernel/types.h"2#include "kernel/stat.h"3#include "kernel/fcntl.h"4#include "user/user.h"56// Stress xv6 logging system by having several processes writing7// concurrently to their own file (e.g., logstress f1 f2 f3 f4)89#define BUFSZ 5001011char buf[BUFSZ];1213int14main(int argc, char **argv)15{16 int fd, n;17 enum { N = 250, SZ=2000 };18 19 for (int i = 1; i < argc; i++){20 int pid1 = fork();21 if(pid1 < 0){22 printf("%s: fork failed\n", argv[0]);23 exit(1);24 }25 if(pid1 == 0) {26 fd = open(argv[i], O_CREATE | O_RDWR);27 if(fd < 0){28 printf("%s: create %s failed\n", argv[0], argv[i]);29 exit(1);30 }31 memset(buf, '0'+i, SZ);32 for(i = 0; i < N; i++){33 if((n = write(fd, buf, SZ)) != SZ){34 printf("write failed %d\n", n);35 exit(1);36 }37 }38 exit(0);39 }40 }41 int xstatus;42 for(int i = 1; i < argc; i++){43 wait(&xstatus);44 if(xstatus != 0)45 exit(xstatus);46 }47 return 0;48}49