shithub: front

Download patch

ref: 6500b3036335699160e7cdfbb7800df0437d520f
parent: 9ae4b3d9fc0b4521422af57d5b5dbb565e51f6d8
author: qwx <qwx@sciops.net>
date: Sun Nov 3 09:58:56 EST 2024

pstree: remove unnecessary globbing and environment pollution (thanks cgnarne, cinap_lenrek)

--- a/rc/bin/pstree
+++ b/rc/bin/pstree
@@ -1,9 +1,7 @@
 #!/bin/rc
-p=0
-if(! ~ $#* 0)
-	p=$1
-cd /proc || exit
-ls -d [0-9]* | sort -n | awk -v 'this='^$p '
+if(~ $#* 0)
+	*=0
+cd /proc && ls | sort -n | awk -v 'this='^$1 '
 function cat(f,	v){
 	getline v < f
 	close(f)
@@ -12,7 +10,7 @@
 BEGIN{
 	OFS="\t"
 }
-{
+/^[0-9]+/ {
 	s = cat($1"/args")
 	if(s == ""){
 		s = cat($1"/status")
@@ -41,7 +39,7 @@
 END{
 	for(i=1; i<=length(pid); i++){
 		p = pid[i]
-		if(!(ppid[p] in proc) && ppid[p] != 0)
+		if(p && !(ppid[p] in proc) && ppid[p] != 0)
 			child[0,++nchild[0]] = p
 	}
 	out(this, "", "", 0)
--