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

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

#include <stdio.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <signal.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...
 
void pkill (pid_t pid, int sig)
 kill wrapper function. More...
 
void pexecl (const char *pathname, const char *arg,...)
 execl wrapper function. More...
 
void psigaction (int signum, const struct sigaction *act, struct sigaction *oldact)
 sigaction wrapper function. More...
 
System V - shared memory

Example
#include <process.h> // #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 <process.h> // #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);
...
// decrement:
struct sembuf down = {0, -1, 0};
psemop(semid, &down, 1);
// or, simply use provided function:
psem_down(semid, 0); // NOTE: there is no sem_down in default library!
...
// increment:
struct sembuf up = {0, 1, 0};
psemop(semid, &up, 1);
// or, simply use provided function:
psem_up(semid, 0); // NOTE: there is no sem_up in default library!
...
// 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()).
 
void psem_down2 (int semid, short unsigned int index1, unsigned int index2)
 Decrements atomically two semaphores in a System V semaphore array (uses psemop()).
 
System V - message queues

Example
#include <process.h> // #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...
 
UNIX pipes

void ppipe (int pipefd[2])
 pipe wrapper function. More...
 
FILE * ppopen (const char *command, const char *type)
 popen wrapper function. More...
 
void ppclose (FILE *stream)
 pclose wrapper function. More...
 

Detailed Description

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

Remarks
Removes defensive programming from native libraries
pshmat
void * pshmat(int shmid, const void *shmaddr, int shmflg)
shmat wrapper function.
process.h
Process, System-V, and POSIX libraries wrapper module.
psemget
int psemget(key_t key, int nsems, int semflg)
semget wrapper function.
pshmget
int pshmget(key_t key, size_t size, int shmflg)
shmget wrapper function.
pmsgsnd
void pmsgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
msgsnd wrapper function.
pmsgget
int pmsgget(key_t key, int msgflg)
msgget wrapper function.
psem_down
void psem_down(int semid, short unsigned int index)
Decrements a semaphore (uses psemop()).
psem_up
void psem_up(int semid, short unsigned int index)
Increment a semaphore (uses psemop()).
psemop
void psemop(int semid, struct sembuf *sops, size_t nsops)
semop wrapper function.