Pagini recente » Cod sursa (job #2680727) | Cod sursa (job #1092426) | Cod sursa (job #3194347) | Cod sursa (job #3221607) | Cod sursa (job #1376399)
#include <sys/types.h>
#include <sys/shm.h>
#include <string.h>
#define SHMSZ (2*1024*1024) /*Ubuntu rejects shared allocations larger than about 2MiB*/
main() {
int shmid;
key_t key = 0xF111; /* Lets use `Fill' as our first ID.*/
char *shm;
while(1) { /* Like malloc, but using shared memory */
if ((shmid = shmget(key, SHMSZ, IPC_CREAT|0666)) < 0){return 1;}/*Get shared memory*/
if ((shm = shmat(shmid, NULL, 0)) == (void *) -1) { return 1; } /*Attach it */
memset(shm,0,SHMSZ); /*Fill it up */
key++; /*On to the next ID*/
}
}