Ask Your Question

How can my program tell when Writer exits?

asked 2015-01-13 23:24:07 +0200

isotherm gravatar image

LO 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 );
        waitpid ( status, &status, 0 );

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

Any ideas?

edit retag flag offensive close merge delete



Lupp gravatar imageLupp ( 2015-01-16 22:37:56 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2015-01-16 21:43:48 +0200

LogicDaemon gravatar image

updated 2015-01-16 22:19:09 +0200

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.

edit flag offensive delete link more


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.

isotherm gravatar imageisotherm ( 2015-03-12 02:31:19 +0200 )edit

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).

LogicDaemon gravatar imageLogicDaemon ( 2015-03-13 14:02:05 +0200 )edit

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

isotherm gravatar imageisotherm ( 2015-03-22 20:11:09 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-01-13 23:24:07 +0200

Seen: 50 times

Last updated: Jan 16 '15