Invoking Unix commands from a Python app
Martin Blume
mblume at socha.net
Fri Dec 16 12:29:04 EST 2005
"Rob Cowie" schrieb
> Excellent... just the thing I was looking for. Thanks.
>
> Does anyone know of a unix app that could be used to
> monitor the duration of processes etc.?
>
man -k account showed me (among others):
acct (2) - switch process accounting on or off
acct (5) - execution accounting file
a short program to start accounting:
(warning: just hacked together)
smail:/home/mblume/wrk/tmp # cat acct.c
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char *argv[])
{
char *pf;
struct stat st_buf;
if (strcmp(argv[1], "NULL") == 0)
{
pf = NULL;
printf("turning accounting off\n");
} // turn accounting off
else if (stat(argv[1], &st_buf) == -1)
{
printf("stat %s failed, error %d=%s\n",
argv[1], errno, strerror(errno));
return 1;
} // stat failed
else
{
// TBD check for a regular file
pf = argv[1];
printf("acct for %s\n", pf);
} // file seems ok
if (acct(pf) == -1)
{
printf("acct failed %d=%s\n",
errno, strerror(errno));
} // oops, acct failed
return 0;
} // main
HTH
Martin
More information about the Python-list
mailing list