C++ Library, mos@ua  0.9
cpplib-mos
process.h File Reference

Process, System-V, and POSIX libraries wrapper module. More...

#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <semaphore.h>

Go to the source code of this file.

Functions

Process handling

pid_t pfork (void)
 fork wrapper function. More...
 
pid_t pwait (int *status)
 wait wrapper function. More...
 
pid_t pwaitpid (pid_t pid, int *status, int options)
 waitpid wrapper function. More...
 
System V - shared memory

Example
#include <sys/shm.h>
...
int shmid;
// creation:
shmid = pshmget(key, size, 0600 | IPC_CREAT | IPC_EXCL);
// or, use existing:
shmid = pshmget(key, 0, 0);
...
// attach shm to pointer address:
void* p = pshmat(shmid, NULL, 0);
...
// detach shm from pointer address:
pshmdt(p);
...
// destroy shm:
pshmctl(shmid, IPC_RMID, NULL);
int pshmget (key_t key, size_t size, int shmflg)
 shmget wrapper function. More...
 
int pshmctl (int shmid, int cmd, struct shmid_ds *buf)
 shmctl wrapper function. More...
 
void * pshmat (int shmid, const void *shmaddr, int shmflg)
 shmat wrapper function. More...
 
void pshmdt (const void *shmaddr)
 shmdt wrapper function. More...
 
System V - semaphores

Example
#include <sys/sem.h>
...
int semid;
// creation:
semid = psemget(key, 1, 0600 | IPC_CREAT | IPC_EXCL); // 1 semaphore!
// or, use existing:
semid = psemget(key, 0, 0);
...
// lock:
struct sembuf down = {0, -1, 0};
psemop(semid, &down, 1);
// or, simply use provided function:
psem_down(semid, 0);
...
//unlock:
struct sembuf up = {0, 1, 0};
psemop(semid, &up, 1);
// or, simply use provided function:
psem_up(semid, 0);
...
// destroy sem 0:
psemctl(semid, 0, IPC_RMID, NULL);
int psemget (key_t key, int nsems, int semflg)
 semget wrapper function. More...
 
int psemctl (int semid, int semnum, int cmd)
 semctl wrapper function. More...
 
int psemctl (int semid, int semnum, int cmd, void *u)
 
void psemop (int semid, struct sembuf *sops, size_t nsops)
 semop wrapper function. More...
 
void psem_up (int semid, short unsigned int index)
 Increment a semaphore (uses psemop()).
 
void psem_down (int semid, short unsigned int index)
 Decrements a semaphore (uses psemop()).
 
System V - message queues

Example
#include <sys/msg.h>
...
typedef struct Item
{
...
} Item;
typedef struct Message
{
long type;
Item item;
} Message;
...
int msgid;
// creation:
msgid = pmsgget(key, 0600 | IPC_CREAT | IPC_EXCL);
// or, use existing:
msgid = pmsgget(key, 0);
...
Message msg;
// send msg:
msg = ...;
pmsgsnd(msgid, &msg, sizeof(Item), 0);
...
// receive msg:
pmsgrcv(msgid, &msg, sizeof(Item), type, 0);
...
// destroy msg:
pmsgctl(msgid, IPC_RMID, NULL);
int pmsgget (key_t key, int msgflg)
 msgget wrapper function. More...
 
int pmsgctl (int msqid, int cmd, struct msqid_ds *buf)
 msgctl wrapper function. More...
 
void pmsgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
 msgsnd wrapper function. More...
 
size_t pmsgrcv (int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
 msgrcv wrapper function. More...
 
POSIX semaphores

sem_t * psem_open (const char *name, int oflag)
 sem_open wrapper function. More...
 
sem_t * psem_open (const char *name, int oflag, mode_t mode, unsigned int value)
 
void psem_close (sem_t *sem)
 sem_close wrapper function. More...
 
void psem_unlink (const char *name)
 sem_unlink wrapper function. More...
 
void psem_init (sem_t *sem, int pshared, unsigned int value)
 sem_init wrapper function. More...
 
void psem_destroy (sem_t *sem)
 sem_destroy wrapper function. More...
 
void psem_wait (sem_t *sem)
 sem_wait wrapper function. More...
 
int psem_trywait (sem_t *sem)
 sem_trywait wrapper function. More...
 
int psem_timedwait (sem_t *sem, const struct timespec *abs_timeout)
 sem_timedwait wrapper function. More...
 
void psem_post (sem_t *sem)
 sem_post wrapper function. More...
 

Detailed Description

Process, System-V, and POSIX libraries wrapper module.

Remarks
Removes defensive programming from native libraries