Hi, i'm playing with procfs API and added a few lines into kernel/fork.c to show the latest process' pid in the /proc/newbie/last_pid entry as an example (modifications are at the end).
But i've a problem as you can see in the shell output below. last_pid shows the latest PID without a problem but the standart proc entries like /proc/{cpuinfo,cmdline,...} dissapear after booting the modified kernel.
root@emektar:~# cat /proc/newbie/last_pid Last created process' PID is 914 root@emektar:~# updatedb & [1] 915 root@emektar:~# ls /proc/[a-z]* newbie self
Anybody could tell me what i am missing, please?
Regards
--- /dev/null 1994-07-18 02:46:18.000000000 +0300
+++ include/linux/newbie.h 2005-02-04 22:05:50.000000000 +0200
@@ -0,0 +1,16 @@
+#ifndef _LINUX_NEWBIE_H
+#define _LINUX_NEWBIE_H
+
+/*
+ * Newbie test structures and functions
+ */
+
+static int
+proc_read_last_pid(char *page, char **start,
+ off_t offset, int count,
+ int *eof, void *data)
+{
+ return sprintf(page, "Last created process' PID is %d\n", *(int *)data);
+}
+
+#endif /* _LINUX_NEWBIE_H */
--- kernel/fork.c.orig 2005-02-04 20:56:25.000000000 +0200 +++ kernel/fork.c 2005-02-04 22:37:59.000000000 +0200 @@ -22,6 +22,8 @@ #include <linux/namespace.h> #include <linux/personality.h> #include <linux/compiler.h> +#include <linux/proc_fs.h> +#include <linux/newbie.h>
#include <asm/pgtable.h> #include <asm/pgalloc.h> @@ -650,6 +652,7 @@ int retval; struct task_struct *p; struct completion vfork; + struct proc_dir_entry *last_pid_dir, *last_pid_root;
if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
return -EINVAL;
@@ -709,6 +712,18 @@
if (p->pid == 0 && current->pid != 0)
goto bad_fork_cleanup;
+ /*
+ * Create a /proc entry containing the
+ * PID of newly created process
+ */
+ if (!(last_pid_root = proc_mkdir("newbie", NULL))) {
+ printk(KERN_WARNING "Cannot create /proc/newbie root\n");
+ }
+ if (!(last_pid_dir = create_proc_read_entry("last_pid", 0444, last_pid_root, \
+ proc_read_last_pid, &p->pid))) {
+ printk(KERN_WARNING "Cannot create /proc/newbie entry\n");
+ }
+
p->run_list.next = NULL;
p->run_list.prev = NULL;
-- M.Baris Demiray
DOS: n., A small annoying boot virus that causes random spontaneous system crashes, usually just before saving a massive project. Easily cured by UNIX. See also MS-DOS, IBM-DOS, DR-DOS.
---- You have to understand, most of these people are not ready to be unplugged. And many of them are no inert, so hopelessly dependent on the system, that they will fight to protect it." Morpheus
begin:vcard fn:M.Baris Demiray n:Demiray;M.Baris org:Ideal Teknoloji adr:;;Teknokent Silikon Bina No:24 ODTU;Ankara;;06531;Turkiye email;internet:baris@xxxxxxxxxxxxxxxxxx title:Yazilim Gelistirici tel;work:+903122101490 tel;fax:+903122101492 x-mozilla-html:FALSE url:http://www.idealteknoloji.com version:2.1 end:vcard