Last active
August 29, 2015 14:01
-
-
Save wmealing/c179523ac43a8f512d9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/fs/proc/array.c b/fs/proc/array.c | |
index 25b1ebc..b2d8d56 100644 | |
--- a/fs/proc/array.c | |
+++ b/fs/proc/array.c | |
@@ -155,11 +155,33 @@ static inline const char *get_task_state(struct task_struct *tsk) | |
return *p; | |
} | |
+static int count_open_files(struct fdtable *fdt) | |
+{ | |
+ int size; | |
+ int i = 0, count = 0; | |
+ | |
+ | |
+ if (!fdt) { | |
+ return 0; | |
+ } | |
+ | |
+ size = fdt->max_fds; | |
+ | |
+ while(i <= size) { | |
+ if(fdt->fd[i] != NULL) | |
+ count++; | |
+ | |
+ i++; | |
+ } | |
+ | |
+ return count; | |
+} | |
+ | |
static inline void task_state(struct seq_file *m, struct pid_namespace *ns, | |
struct pid *pid, struct task_struct *p) | |
{ | |
struct group_info *group_info; | |
- int g; | |
+ int g, fdcount; | |
struct fdtable *fdt = NULL; | |
const struct cred *cred; | |
pid_t ppid, tpid; | |
@@ -192,14 +214,22 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, | |
task_utrace_proc_status(m, p); | |
task_lock(p); | |
- if (p->files) | |
+ if (p->files) { | |
+ spin_lock(&p->files->file_lock); | |
+ | |
fdt = files_fdtable(p->files); | |
+ fdcount = count_open_files(fdt); | |
+ | |
+ spin_unlock(&p->files->file_lock); | |
+ } | |
+ | |
seq_printf(m, | |
"FDSize:\t%d\n" | |
+ "FDCount:\t%d\n" | |
"Groups:\t", | |
- fdt ? fdt->max_fds : 0); | |
- rcu_read_unlock(); | |
+ fdt ? fdt->max_fds : 0, fdcount); | |
+ rcu_read_unlock(); | |
group_info = cred->group_info; | |
task_unlock(p); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment