Linux中pascal与c的数据交换
方法:
通信机制通过shared memory的存取,到达ipc.环境的限制:
本开发系统redhat7.1中Shared Memory的限制:------ Shared Memory Limits --------max number of segments = 4096max seg size (kbytes) = 32768max total shared memory (kbytes) = 8388608min seg size (bytes) = 1 补充:
针对这一点。我们对于shared memory要注意安排,内存块的利用。通过对内存快共享利用。做到及时的沟通pascal和c程序在linux的沟通。 建议:
Shared Memory的充分利用:提升:定义好与内存块表格结构体。必须要有一个限制机制使得大家知道有数据要发送。以及接收。也就是这个表格中。要分不同的区域。 并且提供统一的。存取。发送。控制函数。
Linux中c代码示例
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>
#include <stdlib.h>
main()
{
int id, ret;
int size;
int perm = 0666;
key_t key ;
char *addr;
struct shmid_ds buf ;
key = 1126; //注意此处是要和kylix系统中的key一致,这样才能与其共享
size = 6553;
if ((id=shmget(key, size, IPC_CREAT | perm))== -1) //***
{
printf("shmget (key:0x%x,size:%d,perm:0x%x. pid:%ld)/n",
key, size, perm,getpid());
printf("errno = %d/n", errno);
}
else
{
printf("id = %d/n", id);
}
//***
if ((addr = (char *)shmat(id, (char *)NULL, NULL)) == (char *)-1)
{
printf("shmat pas OK/n");
}
printf("setting addr to 123/n");
*addr = 123;
printf("addr = %x %d/n", addr, *addr);
sleep(50);
if ((ret=shmctl(id, IPC_RMID, NULL))== -1) //***
{
printf("shmctl pas OK /n");
printf("errno = %d/n", errno);
}
else
{
printf("ret = %d/n", ret);
}
}
该博客主要介绍了在Linux系统中实现Pascal与C的数据交换。给出了相关代码,包括头文件引入、共享内存的创建、附加、数据设置以及共享内存的控制等操作,通过这些步骤实现两者间的数据交互。
272

被折叠的 条评论
为什么被折叠?



