Created
June 8, 2018 12:33
-
-
Save ethercflow/06671605f6707b0c83fee617d4ebe706 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#define BLOCKSIZE 1048576 | |
#define N 200 | |
#define BUSYTIME 1000 | |
int main(int argc, char *argv[]) { | |
int fd; | |
if ((fd = open("log.txt", O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) == -1) { | |
fprintf(stderr, "open file failed\n"); | |
} | |
int **p = malloc(N * sizeof(int*));; | |
int i; | |
while (1) { | |
for (i = 0; i < N; i++) { | |
p[i] = malloc(BLOCKSIZE); | |
memset(p[i], '0', BLOCKSIZE); | |
int j; | |
char *q = (char *)(p[i]); | |
for (j = 0; j < BLOCKSIZE; j++) { | |
q[j] = 'c'; | |
} | |
write(fd, q, BLOCKSIZE); | |
usleep(BUSYTIME); | |
} | |
// fprintf(stderr, "malloced\n"); | |
for (i = 0; i < N; i++) { | |
free(p[i]); | |
usleep(BUSYTIME); | |
} | |
// fprintf(stderr, "freed\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment