Data exchange of Pascal and C in Linux

zhaozj2021-02-16  46

Data exchange of Pascal and C in Linux

method:

The communication mechanism reaches the IPC through the access of Shared Memory.

Environmental limit:

The restriction of Shared Memory in redhat7.1 in this development system:

------ Shared Memory Limits --------

Max number of segments = 4096

Max seg size (kbytes) = 32768

Max Total Shared Memory (KBYTES) = 8388608

MIN seg size (bytes) = 1

supplement:

This is aimed at this. We pay attention to the use of Shared Memory. By sharing utilization through memory. Do the timely communication of Pascal and C processes in Linux communication.

Suggest:

Full Utilization of Shared Memory:

Lifting: Define the table structure with the memory block. There must be a restriction mechanism to make you know that there is data to be sent. And receiving. That is, in this form. It is divided into different areas. And provide unified. access. send. Control function.

LINUX C code example

#include

#include

#include

#include

#include

#include

#include

Main ()

{

INT ID, RET;

Int size;

INT perm = 0666;

Key_t key;

Char * addr;

Struct SHMID_DS BUF;

Key = 1126; // Note Here is the same as Key in the Kylix system, so that you can share it

SIZE = 6553;

IF ((id = shmget (key, size, ipc_creat |) == -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);

}

}

转载请注明原文地址:https://www.9cbs.com/read-28275.html

New Post(0)