47 lines
659 B
C
Executable File
47 lines
659 B
C
Executable File
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/resource.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
unsigned int sz = 0;
|
|
void *src = NULL, *dst = NULL;
|
|
int priority = 19;
|
|
int pid = getpid();
|
|
|
|
|
|
if (argc < 2) {
|
|
printf("Usage: ./mc_memcopy sz\n");
|
|
return 1;
|
|
}
|
|
|
|
sz = atoi(argv[1]);
|
|
|
|
src = malloc(sz);
|
|
if (src == NULL)
|
|
return 1;
|
|
|
|
|
|
dst = malloc(sz);
|
|
if (dst == NULL) {
|
|
free(src);
|
|
return 1;
|
|
}
|
|
|
|
if (setpriority(PRIO_PROCESS, pid, priority) == -1) {
|
|
perror("setpriority");
|
|
return 1;
|
|
}
|
|
|
|
while (1) {
|
|
memcpy(dst, src, sz);
|
|
usleep(1000);
|
|
//memcpy(src, dst, sz);
|
|
//usleep(1000);
|
|
}
|
|
|
|
return 0;
|
|
}
|