]> git.itanic.dy.fi Git - rrdd/commitdiff
Count number of sibling processes
authorTimo Kokkonen <kaapeli@ee.oulu.fi>
Wed, 21 May 2008 16:49:48 +0000 (19:49 +0300)
committerTimo Kokkonen <kaapeli@ee.oulu.fi>
Wed, 21 May 2008 16:49:48 +0000 (19:49 +0300)
Makefile
process.c
process.h

index a264262a1ace8f574e67412a781631b1430dd7d1..895910d31fcfe0b8585f00247ad37c616f68669b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,8 @@ clean:
        @$(CC) -MMD -MF .$@.d $(CFLAGS) -c $< -o $@
 
 TAGS:
-       etags *.[ch]
+       @echo -e "\tTAGS\t"
+       @etags *.[ch]
 
 .PHONY: all clean TAGS
 
index 376caa31de428630353592591a0b4e8f63f0d45f..507294a1b0217cb4374c6e192fe60f324fcb93e0 100644 (file)
--- a/process.c
+++ b/process.c
@@ -6,6 +6,7 @@
 
 static int child_count = 0;
 static int parent_count = 0;
+static int process_count = 0;
 
 int get_child_count(void)
 {
@@ -17,6 +18,11 @@ int get_parent_count(void)
        return parent_count;
 }
 
+int get_process_count(void)
+{
+       return process_count;
+}
+
 int do_fork(void)
 {
        int child, error;
@@ -33,6 +39,7 @@ int do_fork(void)
                return child;
        }
 
+       process_count = child_count;
        /* reset child's child count */
        child_count = 0;
        parent_count++;
@@ -210,8 +217,10 @@ int run(const char *cmd, char *const argv[])
        int ofd, efd;
        fd_set rfds;
        int maxfd;
-       char stdoutstr[32], stderrstr[16];
+       char stdoutstr[32], stderrstr[32], indent[16] = { "                " };
 
+       indent[get_parent_count() + 1] = 0;
+               
        if ((child = do_fork()))
            return child;
 
@@ -225,12 +234,10 @@ int run(const char *cmd, char *const argv[])
 
        while (1) {
                char *sptr , *eptr;
-               char rbuf[BUF_SIZE], indent[16] = { ' ' };
+               char rbuf[BUF_SIZE];
                int bytes;
                char *typestr;
 
-               indent[get_parent_count()] = 0;
-               
                maxfd = max(ofd, efd);
                error = select(maxfd, &rfds, NULL, NULL, NULL);
 
index 9b8e40c0f272d6b5c41976c1eab93a8dee130392..d3ec13893b377548d62fa45ed051d13d153bb704 100644 (file)
--- a/process.h
+++ b/process.h
@@ -11,6 +11,7 @@
 
 int get_child_count(void);
 int get_parent_count(void);
+int get_process_count(void);
 
 int do_fork(void);
 int run(const char *p, char *const argv[]);