michee Posted October 11, 2011 Report Share Posted October 11, 2011 Am programul aceasta:#include <arpa/inet.h>#include <stdio.h>#include <netdb.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#include <time.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/wait.h>#include <sys/time.h>#include <netinet/in.h>#include "http_get.c"#include "build.h"#define DEBUG 0 /* change this to 1 for debugging.. */FILE *infile, *outfile;int sock, numforks = 0, timesup = 0, port = 21;int main(int argc, char *argv[]){ char buf[1024]; time_t start; char *file = "out.txt"; int i,j; int max_forks =1000, num_procs = 0; numforks=0; //outfile = fopen(file, "w"); j= open(file,O_RDWR); start = time(0); for(i=1;i<=100000;i++) { if (!(fork())) { sprintf(buf,"Sunt procesul cu pid-ul %d \n",getpid()); write(j,buf, strlen(buf)); exit(0); } else { numforks++; num_procs++; if (numforks > max_forks) for (numforks; numforks > max_forks; numforks--) wait(NULL); } } close(j); //fclose(outfile); printf("Done! completed in %lu seconds, procese %d\n", (time(0) - start),num_procs); exit(EXIT_SUCCESS);}Ar trebui sa creeze 100k procese care sa scrie intr-un fisier, maxim 1000 odata. si outputul fisierului sa fie destul de amestecat (zic eu) ptr ca nu exista nici un fel de locking. Cu toate acestea fisierul e foarte ok, nu e nimik amestecat(varza), sunt aproximativ 97 k linii.De ce se comporta ca si cum ar fi locking desi nu exista locking?De ce sunt doar 97 k linii si nu 100k?Pe ultima linie parintele zice ca a facut 100k procese.Mersi Quote Link to comment Share on other sites More sharing options...
Andrei Posted October 11, 2011 Report Share Posted October 11, 2011 Asta te-ar putea ajuta. FLUENT 6.3 UDF Manual - 7.9 Writing Files in Parallel Quote Link to comment Share on other sites More sharing options...
michee Posted October 11, 2011 Author Report Share Posted October 11, 2011 nu prea vad cum.mersi anyway. Quote Link to comment Share on other sites More sharing options...