Host hangs while starting child process

OSX Mavericks (Xcode5)



I'm somewhat new to JUCE, and I'm trying to setup my plugin with a websocket server. Because libwebsockets wants a blocking poll loop on the main thread, I've build a cmd line juce application that acts as a server, and I'm trying to start it as a child process and open communications to it. Unfortunately, things are hanging on startup, and I'm not sure what could be wrong


My code to launch the child process is based on the juce demo application (Inside of a class I'm instantiating during main plugin instantiation)


if( masterProcess == nullptr ) {

    masterProcess = new WebsocketMasterProcess( *this );

    if( masterProcess->launchSlaveProcess( File("/path/to/child"), commandLineUid) )

        logMessage ("Child process started");



The host dies when it hits this line inside of juce_posix_SharedCode.h ChildProcess::ActiveProcess::ActiveProcess

const pid_t result = fork();


Any ideas about what I might be doing wrong? How can I go about debugging this?

After some further investigation, I've discovered that the child process is actually starting, but it's locking the main thread. Is there something I have to do to stop my child process from blocking the thread it's launched from?

Not sure I fully understand what you mean about it blocking the main thread?

My child process runs a blocking loop (a while loop that never exits). When I launch my child process, whatever thread I launch it from locks until the child process exits. Is that normal behavior, or have I set something up wrong?


I've discovered now that the process is hanging when I'm attempting to send messages to the child process. Right now, the child process (which is sitting inside of a while loop on the main thread) never services its message queue, or yields the main thread. Is it possible that I'm hanging the master process by locking up the main thread of the child while sending messages?


I have no idea if your problem is related but maybe it could help :
( ).

Well yes - obviously if your child process never allows the message loop to run, then it can't receive any messages. There's never a good reason to block the message thread - put any extended processing on a background thread instead.

The problem is not that I don't receive messages, the problem is that the child process is blocking the main thread of my master application.


Also, I'm locking up the main thread of the child process, not the message thread.

Yes! That was my issue exactly, and solved the problem. Thank you!