This page contains few examples given to our customers or given during basic Linux courses we have done.
These examples are the most trivial examples for using several mechanisms such as shared memory, message queue etc.
Some of these examples are free examples taken from other places.
We invite you to send your own examples so this page will be updated for the benefit of all readers.
send your tips to: email@example.com
All tips sent will contain credits to the sender,
including name and email address (if the sender specified that he wants his email published).
Examples must be released in a free license (GPL or BSD or similar).
All examples unless othewise noted are licensed under GNU GPL.
POSIX Threads and semaphores
This simple example shows a small program writing "Hello world" using two threads, each thread writing part of the message.
POSIX Semaphores are used to synchronize the writes.
POSIX message queues
This simple example shows a small program that can operate as both a client and server to send or receive messages.
A message is given as a character string on the command line.
In addition to demonstrating message queues this program also demonstrates using getopt() for parsing command line arguments.
System V shared memory
Example of write to shared memory. Using System V shared memory
This example should be used together with shmread.c
Each string written will be read by shmread.c until the string 'exit' is encountered. System V semaphores are used to synchronize reads from shared memory, thus these two programs can demonstrate the use of System V semaphores.
Example of signals and interval timer
This example uses signal handler for SIGALRM and interval timer to measure number of loop itterations.
A signal handler that prints and resets value of global counter is installed for SIGALRM.
Interval timer is used to send SIGALRM every 1.0 second.