Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Saturate.c
- #define _FILE_OFFSET_BITS 64 /* enable large file support */
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <string.h>
- float nCM=0; /* count of 100's of megs we've written */
- void finish(const char *where) {
- printf("%s: wrote %.1f gig file\n",where,0.1*nCM);
- exit(0);
- }
- void hitError(const char *where) { perror(where); finish(where); }
- void writer(int id)
- {
- char c=0; /* The byte we're writing */
- int cm=100*1024*1024;
- FILE *f[50];
- int r;
- int block[262114];
- int i;
- char fName[40];
- int numFiles=4;
- printf("This is the %i writer, going to create %i files.\nOpened : ", id, numFiles);
- for(i=0; i<numFiles; i++)
- {
- sprintf(fName, "test.%i\0", i);
- f[i]=fopen(fName,"wb");
- if (f[i]==NULL) hitError("Error in fopen of ");
- printf("%s ", fName);
- }
- printf("\n");
- while (nCM<10000) {
- for(i=0; i < numFiles; i++)
- r=fwrite(&block, 1048576, 1, f[i]);
- nCM++;
- }
- }
- int main(int argc, char *argv[])
- {
- int i=0;
- int maxProc=12;
- pid_t pid[50];
- for(i = 0; i < maxProc; ++i) {
- pid[i] = fork();
- if (pid[i] == -1) {
- exit(-1); /* error */
- } else if (pid[i] == 0) {
- /* child */
- writer(i);
- waitpid(pid[i], 0, 0);
- break;
- } else {
- // printf("doing parent things\n");
- }
- }
- // Wait for PIDs to finish
- printf("All done spawning, lets wait for them to finish.\n");
- for(i=0; i<maxProc; i++)
- {
- printf("#%i ,", pid[i]);
- waitpid(pid[i],0,0);
- }
- waitpid(pid[i],0,0);
- printf("Last PID done.");
- writer();
- finish("Done");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement