gtpc2m6i | C/C++ Language Support User's Guide |
This function attaches the shared memory associated with the specified shared memory identifier to the address space of the calling process.
Format
#include <sys/shm.h> void *shmat int shmid, const void *shmaddr, int shmflg);
TPF deviation from POSIX |
---|
This parameter is provided for compatibility with a UNIX environment. The TPF system does not use this parameter. |
Normal Return
If successful, the shmat function returns the address of the shared memory and the shm_nattch field in the shmid_ds data structure is incremented by 1.
Error Return
If unsuccessful, the shmat function returns a value of -1 and sets errno to one of the following:
Programming Considerations
The shmid_ds data structure is defined in the sys/shm.h header file.
Examples
The following example attaches shared memory to the address space of the calling process by using the shared memory identifier returned by the shmget function. The shared memory identifier is removed from the TPF system by using the shmctl function when it is no longer needed.
#include <sys/ipc.h> #include <sys/shm.h> void main(void) { key_t i; int shm; void *addr; struct shmid_ds buf; i = ftok("/usr",3); shm = shmget(i,8000,IPC_CREAT+S_IRUSR+S_IWUSR); addr = shmat(shm,NULL,0); i = shmctl(shm,IPC_RMID,&buf); }
Related Information