0
votes

I am trying to fork() a new process so that I can call a separate console application.

The fork does happen fine and I get a new process id but the process is in sleeping state and does not get active at all even if the browser exits.

I just took the sample plugin project and modified the echo method to do the fork.

A regular console application works fine with the fork code.

Is there something different that has to be taken into account for a firebreath plugin app?

Can someone suggest what might be the issue?

The platform is archlinux 64 bit.

FB::variant PluginTestVZAPI::echo(const FB::variant& msg)
{
    static int n(0);
    fire_echo("So far, you clicked this many times: ", n++);

    // fork
    pid_t pid = fork();
    if(pid == 0) // Child
    {
        m_host->htmlLog("child process");
    }
    else if (pid < 0) // Failed to fork
    {
        m_host->htmlLog("Failed to fork");
        m_host->htmlLog(boost::lexical_cast<std::string>(pid));
    }
    else // Parent
    {
        m_host->htmlLog("Parent process");
    }
    m_host->htmlLog("Child Process PID = " + boost::lexical_cast<std::string>(pid));
    // end fork

    // return "foobar";
    return msg;
}
1
Don't fork a process you don't own and don't know everything about; i'm surprised it doesn't crash right away. Remember, your code is just a guest in the browser or plugin process.Georg Fritzsche
Searching through stackoverflow and in general, the method to launch a new process seems to be using fork. What would be the way to launch a process without using fork?csaket

1 Answers

1
votes

I can't be certain but if I were you I'd try removing the htmlLog calls -- there is no way for you to access the DOM from the child process, so htmlLog won't work at all and it is quite possible that trying to use it in a forked process is causing it to go into an inactive state while it tries (unsuccessfully) to communicate with a browser process that doesn't know about it.

I don't know for certain if this can work or not, but I'd be more than a bit nervous about forking a process that is already a child process of something else; the browser owns the plugin process and communicates with it via IPC, so if you fork that process there could be a lot of code that you don't know about still running and trying to talk to the browser through a now-defunct IPC connection.

My recommendation would be to launch a seperate process, but that's just me. At the very least, you absolutely cannot use anything FireBreath provides for communicating with the browser from the child process.