Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jan 2001 02:57:41 +0900 (JST)
From:      Hajimu UMEMOTO <ume@FreeBSD.org>
To:        current@freebsd.org, hackers@freebsd.org
Subject:   number of processes forked since boot
Message-ID:  <20010116.025742.74757685.ume@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
Hi,

I wish to obtain number of processes forked since boot from userland.
So, I made a patch to intend to commit.
Any comment?

Index: lib/libc/gen/sysctl.3
diff -u lib/libc/gen/sysctl.3.orig lib/libc/gen/sysctl.3
--- lib/libc/gen/sysctl.3.orig	Fri Jan 12 02:39:22 2001
+++ lib/libc/gen/sysctl.3	Tue Jan 16 02:13:19 2001
@@ -294,6 +294,7 @@
 .It "KERN\_UPDATEINTERVAL	integer	no"
 .It "KERN\_VERSION	string	no"
 .It "KERN\_VNODE	struct vnode	no"
+.It "KERN\_NFORKS	integer	no"
 .El
 .Pp
 .Bl -tag -width 6n
@@ -445,6 +446,8 @@
 .Va struct vnode *
 followed by the vnode itself
 .Va struct vnode .
+.It Li KERN_NFORKS
+Number of processes forked.
 .El
 .Ss CTL_MACHDEP
 The set of variables defined is architecture dependent.
Index: sbin/sysctl/sysctl.8
diff -u sbin/sysctl/sysctl.8.orig sbin/sysctl/sysctl.8
--- sbin/sysctl/sysctl.8.orig	Fri Jan 12 02:42:23 2001
+++ sbin/sysctl/sysctl.8	Tue Jan 16 02:13:19 2001
@@ -145,6 +145,7 @@
 .It "kern.bootfile	string	yes
 .It "kern.corefile	string	yes
 .It "kern.logsigexit	integer	yes
+.It "kern.nforks	integer	no
 .It "vm.loadavg	struct	no
 .It "hw.machine	string	no
 .It "hw.model	string	no
Index: sys/kern/kern_fork.c
diff -u sys/kern/kern_fork.c.orig sys/kern/kern_fork.c
--- sys/kern/kern_fork.c.orig	Fri Jan 12 02:46:53 2001
+++ sys/kern/kern_fork.c	Tue Jan 16 02:30:26 2001
@@ -146,6 +146,9 @@
 int	nprocs = 1;				/* process 0 */
 static int nextpid = 0;
 
+static unsigned int nforks = 0;
+SYSCTL_UINT(_kern, KERN_NFORKS, nforks, CTLFLAG_RD, &nforks, 0, "");
+
 /*
  * Random component to nextpid generation.  We mix in a random factor to make
  * it a little harder to predict.  We sanity check the modulus value to avoid
@@ -277,6 +280,8 @@
 	}
 
 	newproc->p_vmspace = NULL;
+
+	nforks++;
 
 	/*
 	 * Find an unused process ID.  We remember a range of unused IDs
Index: sys/sys/sysctl.h
diff -u sys/sys/sysctl.h.orig sys/sys/sysctl.h
--- sys/sys/sysctl.h.orig	Fri Jan 12 02:48:41 2001
+++ sys/sys/sysctl.h	Tue Jan 16 02:13:19 2001
@@ -328,7 +328,8 @@
 #define	KERN_PS_STRINGS		32	/* int: address of PS_STRINGS */
 #define	KERN_USRSTACK		33	/* int: address of USRSTACK */
 #define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
-#define KERN_MAXID		35      /* number of valid kern ids */
+#define KERN_NFORKS		35	/* uint: number of forked */
+#define KERN_MAXID		36      /* number of valid kern ids */
 
 #define CTL_KERN_NAMES { \
 	{ 0, 0 }, \
@@ -366,6 +367,7 @@
 	{ "ps_strings", CTLTYPE_INT }, \
 	{ "usrstack", CTLTYPE_INT }, \
 	{ "logsigexit", CTLTYPE_INT }, \
+	{ "nforks", CTLTYPE_UINT }, \
 }
 
 /*


--
Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
ume@mahoroba.org  ume@bisd.hitachi.co.jp  ume@{,jp.}FreeBSD.org
http://www.imasy.org/~ume/


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010116.025742.74757685.ume>