Initial commit

This commit is contained in:
Bahadir Balban
2008-01-13 13:53:52 +00:00
commit e2b791a3d8
789 changed files with 95825 additions and 0 deletions

51
tasks/test1/src/shmtest.c Normal file
View File

@@ -0,0 +1,51 @@
/*
* Test shmget/shmat/shmdt posix calls.
*
* Copyright (C) 2007 - 2008 Bahadir Balban
*/
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <tests.h>
int shmtest(void)
{
//key_t keys[2] = { 5, 10000 };
key_t keys[2] = { 2, 3 };
void *bases[2] = { 0 , 0 };
int shmids[2];
printf("Initiating shmget()\n");
for (int i = 0; i < 2; i++) {
if ((shmids[i] = shmget(keys[i], 27, IPC_CREAT | 0666)) < 0) {
printf("Call failed.\n");
perror("SHMGET");
} else
printf("SHMID returned: %d\n", shmids[i]);
}
printf("Now shmat()\n");
for (int i = 0; i < 2; i++) {
if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1)
perror("SHMAT");
else
printf("SHM base address returned: %p\n", bases[i]);
}
printf("Now shmdt()\n");
for (int i = 0; i < 2; i++) {
if (shmdt(bases[i]) < 0)
perror("SHMDT");
else
printf("SHM detached OK.\n");
}
printf("Now shmat() again\n");
for (int i = 0; i < 2; i++) {
if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1)
perror("SHMAT");
else
printf("SHM base address returned: %p\n", bases[i]);
}
return 0;
}