From: Craig Small Date: Sun, 4 Sep 2005 23:12:15 +0000 (+0000) Subject: real tty and child threads for pstree X-Git-Tag: v22.11~109 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c80e2b50240387be61e9ed44e67f98ff42d021e;p=psmisc real tty and child threads for pstree --- diff --git a/ChangeLog b/ChangeLog index 71e8b80..6ba7be3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ Changes in 21.7 * pstree works better with uClibc, thanks Mike Frysinger * fuser rewritten: possibly fixes Debian #312560 * fuser prints F instead of f is access is write, thanks to Tet. + * pstree checks to see it is a real tty Debian #326500 + * pstree shows child threads with {commandname} Debian #230924 Changes in 21.6 =============== diff --git a/doc/pstree.1 b/doc/pstree.1 index a7c2ccf..c7b122c 100644 --- a/doc/pstree.1 +++ b/doc/pstree.1 @@ -41,6 +41,15 @@ becomes .sp .fi .PP +.PP +Child threads of a process are found under the parent process and are shown +with the process name in curly braces, e.g. +.nf +.sp + icecast2\-\-\-13*[{icecast2}] +.sp +.fi +.PP If \fBpstree\fR is called as \fBpstree.x11\fR then it will prompt the user at the end of the line to press return and will not return until that has happened. This is useful for when \fBpstree\fR is run in a xterminal. diff --git a/src/pstree.c b/src/pstree.c index f118161..ee78422 100644 --- a/src/pstree.c +++ b/src/pstree.c @@ -624,6 +624,41 @@ read_proc (void) (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy, &ppid) == 4) */ + { + DIR *taskdir; + struct dirent *dt; + char *taskpath; + char *threadname; + int thread; + + if (!(taskpath = malloc(strlen(path) + 10))) { + exit (2); + } + sprintf (taskpath, "%s/task", path); + + if ((taskdir=opendir(taskpath))!=0) { + /* if we have this dir, we're on 2.6 */ + if (!(threadname = malloc(strlen(comm) + 3))) { + exit (2); + } + sprintf(threadname,"{%s}",comm); + while ((dt = readdir(taskdir)) != NULL) { + if ((thread=atoi(dt->d_name)) !=0) { + if (thread != pid) { +#ifdef FLASK_LINUX + add_proc(threadname, thread, pid, st.st_uid, NULL, 0, sid); +#else /*FLASK_LINUX*/ + add_proc(threadname, thread, pid, st.st_uid, NULL, 0); +#endif /*FLASK_LINUX*/ + } + } + } + free(threadname); + (void) closedir(taskdir); + } + free(taskpath); + } + if (!print_args) #ifdef WITH_SELINUX add_proc(comm, pid, ppid, st.st_uid, NULL, 0, scontext); @@ -779,10 +814,10 @@ main (int argc, char **argv) * command-line options, if given. */ - if (!strcmp(nl_langinfo(CODESET), "UTF-8")) { + if (isatty(1) && !strcmp(nl_langinfo(CODESET), "UTF-8")) { /* Use UTF-8 symbols if the locale's character set is UTF-8. */ sym = &sym_utf; - } else if ((termname = getenv ("TERM")) && \ + } else if (isatty (1) && (termname = getenv ("TERM")) && \ (strlen (termname) > 0) && \ (setupterm (NULL, 1 /* stdout */, NULL) == OK) && \ (tigetstr ("acsc") > 0)) {