C++ Library, mos@ua
0.9
cpplib-mos
|
Process, System-V, and POSIX libraries wrapper module. More...
Files | |
file | process.h |
Process, System-V, and POSIX libraries wrapper module. | |
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 | |
| |
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 | |
| |
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 | |
| |
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... | |
Process, System-V, and POSIX libraries wrapper module.
This module removes defensive programming approach of native libraries.
All implemented functions, have exactly the same arguments and/or result of the original function, with the exception of returning an error indication.
Errors are handled by the implementation of two policies:
stderr
(with the identification of the errno error, and the precise location the call), generates a segmentation fault (enabling a stack trace within a debugger like gdb
), and exits program execution;int
exception with the (errno) status error returned by the original function.System V group of IPC mechanisms
There are three resources for IPC: shared memory, semaphores, and message queues.
Common to all, is resource handling through a non-negative integer identifier. After proper creation and initialization, different processes can establish communication using the same integer identifier.
A key (key_t
) is used to establish this common identifier. There are three possibilities to define a key:
IPC_PRIVATE
: In this case an alternative channel to communicate the identifier between processes is necessary (parent/child fork, file system, ...).ftok
function to generate a key from a path and a byte integer.Usage:
msgget
/semget
/shmget
with a key and IPC_CREAT
and IPC_EXCL
flagsmsgget
/semget
/shmget
with a key and other arguments as zeropid_t pfork | ( | void | ) |
pid_t pwait | ( | int * | status | ) |
pid_t pwaitpid | ( | pid_t | pid, |
int * | status, | ||
int | options | ||
) |
int pshmget | ( | key_t | key, |
size_t | size, | ||
int | shmflg | ||
) |
shmget
wrapper function.
Documentation in
man 2 shmget
int pshmctl | ( | int | shmid, |
int | cmd, | ||
struct shmid_ds * | buf | ||
) |
void* pshmat | ( | int | shmid, |
const void * | shmaddr, | ||
int | shmflg | ||
) |
void pshmdt | ( | const void * | shmaddr | ) |
int psemget | ( | key_t | key, |
int | nsems, | ||
int | semflg | ||
) |
semget
wrapper function.
nsems > 0
Documentation in
man 2 semget
int psemctl | ( | int | semid, |
int | semnum, | ||
int | cmd | ||
) |
void psemop | ( | int | semid, |
struct sembuf * | sops, | ||
size_t | nsops | ||
) |
int pmsgget | ( | key_t | key, |
int | msgflg | ||
) |
int pmsgctl | ( | int | msqid, |
int | cmd, | ||
struct msqid_ds * | buf | ||
) |
void pmsgsnd | ( | int | msqid, |
const void * | msgp, | ||
size_t | msgsz, | ||
int | msgflg | ||
) |
size_t pmsgrcv | ( | int | msqid, |
void * | msgp, | ||
size_t | msgsz, | ||
long | msgtyp, | ||
int | msgflg | ||
) |
sem_t* psem_open | ( | const char * | name, |
int | oflag | ||
) |
void psem_close | ( | sem_t * | sem | ) |
sem_close
wrapper function.
sem != NULL
Documentation in
man 3 sem_close
void psem_unlink | ( | const char * | name | ) |
void psem_init | ( | sem_t * | sem, |
int | pshared, | ||
unsigned int | value | ||
) |
sem_init
wrapper function.
sem != NULL
Documentation in
man 3 sem_init
void psem_destroy | ( | sem_t * | sem | ) |
sem_destroy
wrapper function.
sem != NULL
Documentation in
man 3 sem_destroy
void psem_wait | ( | sem_t * | sem | ) |
sem_wait
wrapper function.
sem != NULL
Documentation in
man 3 sem_wait
int psem_trywait | ( | sem_t * | sem | ) |
sem_trywait
wrapper function.
sem != NULL
Documentation in
man 3 sem_trywait
!=0
) on success, false (0
) if semaphore is zero int psem_timedwait | ( | sem_t * | sem, |
const struct timespec * | abs_timeout | ||
) |
sem_timedwait
wrapper function.
sem != NULL
Documentation in
man 3 sem_timedwait
!=0
) on success, false (0
) if timeout has expired before being able to decrement the semaphore void psem_post | ( | sem_t * | sem | ) |
sem_post
wrapper function.
sem != NULL
Documentation in
man 3 sem_post