How can my program tell when Writer exits?

LO 4.3.3.2 English Writer
Ubuntu 14.10 English

I have a program that forks and spawns a Writer instance, and I’d like to be able to determine when the user has terminated the instance.

int status;
switch ( status = fork () ) {
    case 0:
        // child
        execlp ( "lowriter", "lowriter", "test.odt", NULL );
        _exit ( EXIT_FAILURE );
        break;
    default:
        waitpid ( status, &status, 0 );
        break;
}

The problem is that waitpid() returns EXIT_SUCCESS immediately, rather than waiting for the Writer window to be closed.

Any ideas?

(deleted!)

It exits immediately, because, probably, there was already LibreOffice process, and new one just passed document to it.

Better way to watch for when document is closed, is to watch for lock file.

It’s always named .~lock.*#, where * is original document name. Once file is opened, lockfile is created. When document closed, lockfile gets deleted. So, you just first wait for lockfile, then you wait for it’s non-existence, and you’re fine.

No, when investigating the problem I made sure there were no other LO instances running. I think it more likely that lowriter exits immediately after spawning some other executable to do the actual work. At any rate, following the lock file is surely the way to go.

well, I just guessed that from Windows perspective, didn’t actually check it under linux. Yep, lowriter is basically just launcher for soffice.bin with some additional arguments, so maybe it indeed exits immediately on linux (not on windows, except if there is another running instance).

Confirmed - the linux inotify API detects and reports the deletion of the lock file. Thanks for the tip!