本篇文章给大家谈谈获取所有共享 交换温柔2中文屏幕 idc 交换温柔2中文屏幕 交换温柔2中文屏幕 ,以及获取所有共享交换温柔2中文屏幕idc交换温柔2中文屏幕交换温柔2中文屏幕错误对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
91影院地址发布页
1、91约炮网址在线免费观看2、91影院国 产一区二区久久3、91约炮网址最新网址4、91约炮网址在线免费观看
91约炮网址在线免费观看
共享交换温柔2中文屏幕的函数有以下几个:
(1)int shmget(key_t key, int size, int shmflg),开辟或使用一块共享交换温柔2中文屏幕。
(2)void *shmat(int shmid, const void *shmaddr, int shmflg), 将参数shmid所指向的共享交换温柔2中文屏幕与当前进程连接。
当使用某共享交换温柔2中文屏幕时,需要先使用shmat,达成连接。
(3)int shmdt(const void *shmaddr),将先前用shmat连接的共享交换温柔2中文屏幕与当前进程解除连接。参数shmaddr为shmat返回的共享交换温柔2中文屏幕的地址。
在完成对共享交换温柔2中文屏幕的使用后,需要使用shmdt解除连接。
(4)int shmctl(int shmid, int cmd, struct shmid_ds *buf),控制交换温柔2中文屏幕的操作。当cmd为IPC_RMID时,删除shmid所指的共享交换温柔2中文屏幕。
这些函数的表头文件为sys/ipc.h和sys/shm.h
下面给出一个使用共享交换温柔2中文屏幕实现进程间通信的例子:进程A开辟一块新的共享交换温柔2中文屏幕,进程B修改这个共享交换温柔2中文屏幕,进程C打印输出这个共享交换温柔2中文屏幕的内容,进程D删除这个共享交换温柔2中文屏幕。
进程BCD运行的命令格式为:命令 共享交换温柔2中文屏幕ID,如./output 123432。
进程A交换温柔2中文屏幕如下:
int main()
{
int shmid;
shmid = shmget(IPC_PRIVATE, SIZE, IPC_CREAT | 0600);
if (shmid 0)
{
perror(“shmget error”);
exit(1);
}
printf(“create shared memory OK. shmid=%d/n”, shmid);
return 0;
}
进程B交换温柔2中文屏幕如下:
int main(int argc, char *argv[])
{
int shmid;
char *shmaddr;
if (argc != 2)
{
perror(“argc error/n”);
exit(1);
}
shmid = atoi(argv[1]);
shmaddr = (char *)shmat(shmid, NULL, 0);
if ((int )shmaddr == -1)
{
perror(“shmat error./n”);
exit(1);
}
strcpy(shmaddr, “hello, world!”);
shmdt(shmaddr);
return 0;
}
进程C交换温柔2中文屏幕如下:
int main(int argc, char *argv[])
{
int shmid;
char *shmaddr;
if (argc != 2)
{
printf(“argc error/n”);
exit(1);
}
shmid = atoi(argv[1]);
shmaddr = (char *)shmat(shmid, NULL, 0);
if ((int )shmaddr == -1)
{
perror(“shmat error./n”);
exit(1);
}
printf(“%s/n”, shmaddr);
shmdt(shmaddr);
return 0;
}
进程D交换温柔2中文屏幕如下:
int main(int argc, char *argv[])
{
int shmid;
if (argc != 2)
{
perror(“argc error/n”);
exit(1);
}
shmid = atoi(argv[1]);
shmctl(shmid, IPC_RMID, NULL);
return 0;
}
91影院国 产一区二区久久
#includestdlib.h
#includestring.h
int copymem(void*souceptr,void*destptr,int infolen)
{
return memcpy(destptr,souceptr,infolen);// 复制源去目标地址,位数为Infolen
}
91约炮网址最新网址
#include stdio.h
#include malloc.h
#include string.h
char *memory, *currentPointer;
void ShareMemory( char function, char *a )
{
switch (function)
{
case ‘c’:
memory = ( char * )malloc( 65 * sizeof( char ) );
memory[64] = 0;
currentPointer = memory;
break;
case ‘r’:
printf(“%s”, memory);
printf(“\n”);
break;
case ‘w’:
strcpy( currentPointer, a );
while( *currentPointer != ‘\0’ )
{
currentPointer++;
}
break;
case ‘d’:
free(memory);
break;
default:
printf(“wrong parameter!”);
}
}
int main()
{
char *a = “aaaaa”;
ShareMemory(‘c’, a);
ShareMemory(‘r’, a);
ShareMemory(‘w’, a);
a = “bbbbb”;
ShareMemory(‘w’, a);
ShareMemory(‘r’, a);
ShareMemory(‘d’, a);
return 0;
}
91约炮网址在线免费观看
分配交换温柔2中文屏幕空间然后读取
#includestdio.h
#includestdlib.h
intfilelength(FILE*fp);
char*readfile(char*path);
intmain(void)
{
FILE*fp;
char*string;
string=readfile(“c:/c.c”);
printf(“读入完毕\n按任意键释放交换温柔2中文屏幕资源\n”);
//printf(“%s\n”,string);
system(“pause”);
return0;
}
char*readfile(char*path)
{
FILE*fp;
intlength;
char*ch;
if((fp=fopen(path,”r”))==NULL)
{
printf(“openfile%serror.\n”,path);
exit(0);
}
length=filelength(fp);
ch=(char*)malloc(length);
fread(ch,length,1,fp);
*(ch+length-1)=’\0′;
returnch;
}
intfilelength(FILE*fp)
{
intnum;
fseek(fp,0,SEEK_END);
num=ftell(fp);
fseek(fp,0,SEEK_SET);
returnnum;
}
扩展资料
cLinux进程间通信共享交换温柔2中文屏幕:
#include”comm.h”
staticintcommShm(intsize,intflags)//创建共享交换温柔2中文屏幕
{
key_tkey=ftok(PATHNAME,PROJ_ID);
if(key0){
perror(“ftok”);
return-1;
}
intshmid=shmget(key,size,flags);
if(shmid0){
perror(“shmget”);
return-2;
}
returnshmid;
}
intcreateShm(intsize)
{
returncommShm(size,IPC_CREAT|IPC_EXCL);
}
intgetShm(intsize)//获取共享交换温柔2中文屏幕
{
returncommShm(size,IPC_CREAT);
}
intdestoryShm(intshmid)//销毁共享交换温柔2中文屏幕
{
if(shmctl(shmid,IPC_RMID,NULL)0){
perror(“shmctl”);
return-3;
}
}
关于获取所有共享交换温柔2中文屏幕idc交换温柔2中文屏幕交换温柔2中文屏幕和获取所有共享交换温柔2中文屏幕idc交换温柔2中文屏幕交换温柔2中文屏幕错误的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。