Files
mckernel/test/issues/1181/shm_large.c
Ken Sato dfd23c3ebe prctl: Add support for PR_SET_THP_DISABLE and PR_GET_THP_DISABLE
Change-Id: I04c5568a9eb78bcac632b734f34bba49cf602c4d
Refs: #1181
2019-01-22 05:40:56 +00:00

38 lines
615 B
C

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define SHM_SIZE (16 << 20)
int main(int argc, char **argv)
{
void *shm = NULL;
key_t key = ftok(argv[0], 0);
int shmid;
struct shmid_ds buf;
shmid = shmget(key, SHM_SIZE, IPC_CREAT | 0660);
if (shmid < 0) {
perror("shmget: ");
return -1;
}
shm = shmat(shmid, NULL, 0);
if (!shm) {
perror("shmat: ");
return -1;
}
printf("shmat to %p, size: %ldM\n", shm, SHM_SIZE / 1024 / 1024);
memset(shm, 0, SHM_SIZE);
shmdt(shm);
shmctl(shmid, IPC_RMID, &buf);
return 0;
}