-
-
Save chrishiestand/6383005 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 <unistd.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
main(argc,argv) | |
int argc; | |
char **argv; | |
{ | |
char *array; | |
unsigned int n_bytes,t,i,j; | |
if(argc < 3) | |
{ | |
printf("\nUsage: %s n_bytes sleep_time\n\n",argv[0]); | |
exit(1); | |
} | |
n_bytes = strtoul(argv[1],NULL,10); | |
t = strtoul(argv[2],NULL,10); | |
printf("allocating %u bytes...\n",n_bytes); | |
if ((array=(char *)malloc(n_bytes*sizeof(char)))==NULL) { | |
fprintf(stderr, "File %s, Line %ld: Out of memory while allocating %u bytes.\n", __FILE__, (long)__LINE__, n_bytes); | |
exit(1); | |
} | |
printf("writing %u bytes...\n",n_bytes); | |
for (i=0;i<n_bytes;i++) { | |
array[i] = i; | |
} | |
printf("reading %u bytes...\n",n_bytes); | |
for (i=0;i<n_bytes;i++) { | |
j=array[i]; | |
} | |
printf("sleeping for %u seconds...\n",t); | |
sleep(t); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment