Take a look at IPC::Semaphore & KeyedMutex. I cannot help further as I don't run Linux.
In reply to Re^3: logging of process by BrowserUk in thread logging of process by sandy1028