I got an answer in a different forum (thanks Rainer). It's done mostly by
locking a resource like that:
struct flock lock;
int fd, rc;
fd = open("/path/to/FileOrDevice", O_RDWR);
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = lock.l_len = 0;
rc = fcntl(fd, F_SETLK, &lock);
If the file is unlocked, rc will be 0 and the process will have
acquired an exlusive lock on it. Otherwise, rc will be -1 and errno
contain a 'suitable error code' (either EAGAIN or EACCESS).
Anyway, it's a bit offtopic here.
--
Guillaume Dargaud
http://www.gdargaud.net/