will not return until that has happened. This is useful for when
.B pstree
is run in a xterminal.
+.PP
+Certain kernel or mount parameters, such as the hidepid option for procfs,
+will hide information for some processes. In these situations
+.B pstree
+will attempt to build the tree without this information, showing process
+names as question marks.
+
.SH OPTIONS
.IP \fB\-a\fP
Show command line arguments. If the command line of a process is
static int dumped = 0; /* used by dump_by_user */
static int charlen = 0; /* length of character */
+static void fix_orphans(void);
/*
* Allocates additional buffer space for width and more as needed.
* The first call will allocate the first buffer.
for (walk = list; walk; walk = walk->next)
if (walk->pid == pid)
- break;
- return walk;
+ return walk;
+ return NULL;
}
#ifdef WITH_SELINUX
parent = new_proc("?", ppid, 0, scontext);
#else /*WITH_SELINUX */
parent = new_proc("?", ppid, 0);
-#endif /*WITH_SELINUX */
- /* When using kernel 3.3 with hidepid feature enabled on /proc
- * then we need fake root pid */
- if (!isthread && pid != 1) {
- PROC *root;
- if (!(root = find_proc(1))) {
-#ifdef WITH_SELINUX
- root = new_proc("?", 1, 0, scontext);
-#else /*WITH_SELINUX */
- root = new_proc("?", 1, 0);
#endif
- }
- add_child(root, parent);
- parent->parent = root;
- }
}
add_child(parent, this);
this->parent = parent;
free(path);
}
(void) closedir(dir);
+ fix_orphans();
if (print_args)
free(buffer);
if (empty) {
}
}
+static void fix_orphans(void)
+{
+ /* When using kernel 3.3 with hidepid feature enabled on /proc
+ * then we need fake root pid and gather all the orphan processes
+ * that is, processes with no known parent
+ * As we cannot be sure if it is just the root pid or others missing
+ * we gather the lot
+ */
+ PROC *root, *walk;
+
+ if (!(root = find_proc(1))) {
+#ifdef WITH_SELINUX
+ root = new_proc("?", 1, 0, scontext);
+#else /*WITH_SELINUX */
+ root = new_proc("?", 1, 0);
+#endif
+ }
+ for (walk = list; walk; walk = walk->next) {
+ if (walk->pid == 1 || walk->pid == 0)
+ continue;
+ if (walk->parent == NULL) {
+ add_child(root, walk);
+ walk->parent = root;
+ }
+ }
+}
+
static void usage(void)
{
fprintf(stderr,