⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test11_2.txt

📁 linux under the C programming which complementary with the book of <linux under the C programming
💻 TXT
字号:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>

#define ARRAY_SIZE 4000
#define MALLOC_SIZE 10000
#define SHM_SIZE 10000
#define SHM_MODE (SHM_R|SHM_W)

void printf_shmpemid(struct shmid_ds *buf);

char array[ARRAY_SIZE];

int main(void)
{
    	int shmid;
    	char *ptr, *shmptr;
    	struct shmid_ds shmds;
    
    	printf("array[ ] form %x to %x \n ", &array[0], &array[ARRAY_SIZE]);
    	printf("stack around %x \n",&shmid);

	if(!(ptr=malloc(MALLOC_SIZE)))
	{
    		fprintf(stderr, "malloc error\n");
    		exit(1);
	}

	if((shmid=shmget(IPC_PRIVATE, SHM_SIZE, SHM_MODE))<0)
	{
    		fprintf(stderr, "shmget error!\n");
    		exit(1);
	}

	if((shmptr=shmat(shmid, 0, 0))==(void*)-1)
	{
    		fprintf(stderr, "shmat error!\n");
    		exit(1);
	}

	if(shmctl(shmid, IPC_STAT, &shmds)==-1)
	{
      		fprintf(stderr,"GET shmid_ds ERROR!\n");
    		exit(1);
	}
	printf_shmpemid(&shmds);

	if(shmctl(shmid, IPC_RMID, 0)<0)
	{
      		fprintf(stderr, "shmctl error\n");
    		exit(1);
	}
	exit(0);
}


void printf_shmpemid(struct shmid_ds *buf)
{
    	printf("Struct ipc_perm:\n"); 
    	printf("  uid=%d:\n", buf->shm_perm.uid); 
    	printf("  gid=%d:\n", buf->shm_perm.gid); 
    	printf("  cuid=%d:\n", buf->shm_perm.cuid); 
    	printf("  cgid=%d:\n", buf->shm_perm.cgid); 
    
	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -