13 interprocess communication (root/user), Ktam3874/pitx software guide, And now the include-file 'fifo.h – Kontron KTAM3874-pITX User Manual

Page 263

Advertising
background image

KTD-S0057-I

Page 259 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide

10.13 Interprocess Communication (Root/User)

Many examples in this guide require root access. If you want to retain the user permissions the easiest way
is based on InterProcess Communication (IPC) between a root (server) and a user (client) program. For
background operation the server part can be realized as a Daemon. A number of possible communication
types exist: shared memory, mapped memory, pipes, FIFOs (named pipes) and sockets. The following
demonstration programs only use FIFOs. Any process has the ability to open or close the FIFO; the proces-
ses on either end of the pipe need not be related to each other. A FIFO can possess multiple readers or
multiple writers.
As a first step the sample programs run as normal applications in a terminal window, one as root (server)
and the other one as user (client).

One possible Makefile (server) might look like this:

CC := arm-linux-gnueabihf-gcc -march=armv7

all: server

server.o: server.c

server: server.o

$(CC) -o $@ server.o

clean:

rm server server.o

One possible Makefile (client) might look like this:

CC := arm-linux-gnueabihf-gcc -march=armv7

all: client

client.o: client.c

client: client.o

$(CC) -o $@ client.o

clean:

rm client client.o

and now the Include-file 'fifo.h':

/* Include file for server & client application

* Copyright (c) 2014 Kontron Technology A/S

* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License. */

#ifndef FIFO_H
#define FIFO_H

#define RD_SIZE

32

#define WR_SIZE

32

#define POLL_TIME

5

/* milliseconds */

Advertising
This manual is related to the following products: