32 lines
634 B
C
32 lines
634 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#include <time.h>
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
if (argc!=3) {
|
||
|
printf("Usage: %s <file> <string>", argv[0]);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
FILE * f = fopen(argv[1], "w+");
|
||
|
if (f==NULL) {
|
||
|
printf("Error while opening file %s\n", argv[1]);
|
||
|
return -2;
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i<2000; i++) {
|
||
|
fprintf(f, "%s", argv[2]);
|
||
|
usleep(rand()%100);
|
||
|
}
|
||
|
|
||
|
|
||
|
fclose(f);
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Si programme executé plusieurs fois sur le même fichier simultanément, deuxième programme lancé prend le pas après un court temps
|
||
|
*/
|