From 1c8216a6cecf0b21294395c827dcf640e6ac8c0e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 30 Nov 2015 06:58:06 -0600 Subject: [PATCH] Add group ID or parent PID to procfs output (if available) --- fs/procfs/fs_procfsproc.c | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 325c2286f2..b01b2cbb8e 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -72,6 +72,18 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* See include/nuttx/sched.h: */ + +#undef HAVE_GROUPID + +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) +# define HAVE_GROUPID 1 +#endif + +#ifdef CONFIG_DISABLE_PTHREAD +# undef HAVE_GROUPID +#endif + /* Determines the size of an intermediate buffer that must be large enough * to handle the longest line generated by this logic. */ @@ -362,6 +374,8 @@ static FAR const struct proc_node_s *proc_findnode(FAR const char *relpath) * 123456789012345678901234567890 * Name: xxxx... Task/thread name (See CONFIG_TASK_NAME_SIZE) * Type: xxxxxxx {Task, pthread, Kthread, Invalid} + * PPID: xxxxx Parent thread ID + * Group: xxxxx Group ID * State: xxxxxxxx,xxxxxxxxx {Invalid, Waiting, Ready, Running, Inactive}, * {Unlock, Semaphore, Signal, MQ empty, MQ full} * Flags: xxx N,P,X @@ -375,6 +389,9 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen, off_t offset) { +#ifdef HAVE_GROUPID + FAR struct task_group_s *group; +#endif FAR const char *policy; FAR const char *name; size_t remaining; @@ -421,6 +438,30 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, return totalsize; } +#ifdef CONFIG_SCHED_HAVE_PARENT +#ifdef HAVE_GROUPID + group = tcb->group; + DEBUGASSERT(group); + + linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "Group:", + group->tg_pgid); +#else + linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "PPID:", + tcb->ppid); +#endif + + copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset); + + totalsize += copysize; + buffer += copysize; + remaining -= copysize; + + if (totalsize >= buflen) + { + return totalsize; + } +#endif + /* Show the thread state */ linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%s\n", "State:",