On 18-11-10 16:27, Bas van der Vlies wrote:
> Version: Community Edition 3.1.0
> os: debian
>
> I want to select proccess that have as parent "1". So we can watch for
> example ntpd.
>
> I have this process_select body:
> {
>           ppid            =>  irange("1", "1");
>           process_result  =>  "ppid";
> }
>
>
> But this fails on our systems:
> Setting local variable "match.0" context; $(0) = ntpd
> SelectProcess(ntp       7391  0.0  0.0  28240  1700 ?        Ss   16:00
> 0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 108:111)
> SplitProcLine(ntp       7391  0.0  0.0  28240  1700 ?        Ss   16:00
> 0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 108:111)
>
> The parent process is '?' for cfengine3. So this fails.  I suspect that the
> ps command for debian systems is not correct.
>
>
>
maybe is better to use libproc for reading the process table than depending 
on the command ps (also uses libproc library). Here a small example:

cc -o read_proc read_proc.c -lproc

{{{
#include <stdlib.h>
#include <stdio.h>
#include <proc/readproc.h>
#include <string.h>

int main()
{
         proc_t **pptr;
         proc_t *tmp;
         pptr = readproctab(PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTAT);

         for(; *pptr; pptr++) {
                 tmp = *pptr;
                 if ( tmp->cmdline != NULL )
                 {
                         printf("%d\n", strlen(*tmp->cmdline));
                         printf("tmp->cmdline = %s\n", *tmp->cmdline);
                 }
                 printf("tmp->tid = %d\n", tmp->tid);
                 printf("tmp->egid = %d\n", tmp->egid);
                 printf("tmp->egid = %d\n", tmp->egid);
                 printf("tmp->ppid = %d\n", tmp->ppid);
         }
}


-- 
********************************************************************
*  Bas van der Vlies                    e-mail: b...@sara.nl       *
*  SARA - Academic Computing Services   Amsterdam, The Netherlands *
********************************************************************
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to