Skip to contentSkip to conversation

wait for childs of a child process

DISCUSSION Gauvain Pocentek 3 participants 4 messages Feb 9, 2009

lore
Share & tools
lore
#0 lore raw

Hello,

I have to monitor applications on a system (users who run the application, how long, etc.), but I'm having troubles with applications which fork during startup (openoffice for instance).

Here is a snippet of what I planned to use (checks omitted to simplify):

####################################
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()

{
    int status;
    pid_t p = fork();
    if (p == 0)
        system ("soffice");
    else if (p > 0)
    {
        waitpid (p, &status, 0);
        printf ("done\n");
    }

    return 0;
}

####################################

Is there a way to make wait() or an other syscall monitor the process' children, or is patching openoffice (and other apps behaving in the same way) the only solution?

Thanks,
Gauvain Pocentek

#1 lore raw
Quoted 3 lines · Gauvain Pocentek

I have to monitor applications on a system (users who run the application, how long, etc.), but I'm having troubles with applications which fork during startup (openoffice for instance).

Are you sure that the process accounting on Linux doesn't cover your needs and you need a custom solution?

Signature · 1 line
 Michael Iatrou (brzh)
#2 lore raw
Quoted 8 lines · Michael Iatrou
Quoted 3 lines · Gauvain Pocentek

I have to monitor applications on a system (users who run the application, how long, etc.), but I'm having troubles with applications which fork during startup (openoffice for instance).

Are you sure that the process accounting on Linux doesn't cover your needs and you need a custom solution?

Well I wasn't aware that such tool existed. It will probably help to use this instead of reinventing the wheel.

Thanks to you and ben (who had the same idea).

Gauvain

NB: sorry for the typo in the subject.

#3 lore raw
In reply to Gauvain Pocentek
Quoted 28 lines · Gauvain Pocentek

Hello,

I have to monitor applications on a system (users who run the application, how long, etc.), but I'm having troubles with applications which fork during startup (openoffice for instance).

Here is a snippet of what I planned to use (checks omitted to simplify):

####################################
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()

{
    int status;
    pid_t p = fork();
    if (p == 0)
        system ("soffice");
    else if (p > 0)
    {
        waitpid (p, &status, 0);
        printf ("done\n");
    }

    return 0;
}
Quoted 8 lines

####################################

Is there a way to make wait() or an other syscall monitor the process' children, or is patching openoffice (and other apps behaving in the same way) the only solution?

Thanks,
Gauvain Pocentek

Would not be simpler to use Unix's pacct feature ? It may not be enabled, though, on some linux distro.

- ben
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html