Listing 4 (lidar_read.c) 
/* ---
   lidar_read task. This task initializes shared 
   memory, waits for a  message, reads a frame 
   buffer from the digitizer, and sends a message
   to the write task when the frame buffer is full.  
--- */

#include    "lidar.h"

main()
{
    int     ieee_488;
    int     read_qid, write_qid;
    int     alive_sem;
    int     terminate = FALSE;
    char    *fb_shm; 
    message mptr;

    /* --- set process prioprity --- */
    setpriority (PRIO_PROCESS, 0, LIDAR_READ);

    /* --- open message queues --- */
    read_qid = msgget (READ_Q, 0666 | IPC_CREAT);
    write_qid = msgget (WRITE_Q, 0666 | IPC_CREAT);

    /* --- get semaphore --- */
    alive_sem = sem_get (ALIVE_KEY, 0);

    /* -- create shared memory frame buffers  -- */
    fb_shm = shmat(shmget (FB_KEY, FRAME_SIZE*N_FRAMES, 
                   0666|IPC_CREAT), 0, 0);

    /* --- open ieee file and set up digitizer --- */
    ieee_488 = init_digitizer ();

    /* --- tell the world we're open for business --- */
    sem_signal (alive_sem);

    /* --- while lidar data acquisition program running --- */
    while (!terminate) {
       /* --- wait for a message to start read --- */
       msgrcv (read_qid, &mptr, MSG_SIZE, ANYTYPE, NOFLAGS);

       /* --- check for quit --- */
       if (mptr.key == QUIT)
          terminate = 1;
       else 
          read_digitizer (ieee_488, fb_shm + 
                          mptr.key * FRAME_SIZE);
       
       /* --- send the message on to the write task --- */
       msgsnd (write_qid, &mptr, MSG_SIZE, IPC_NOWAIT);
       }

    /* --- close digitizer file --- */
    close_digitizer (ieee_488);

    /* --- release memory --- */
    shmdt (fb_shm);
}
