Reputation: 93
Hello i am trying to recursevely print PPID's (parent, grandparent and so on). I wrote a function:
function parents(){
smth=$(ps -o ppid= -p "$1")
echo $smth
if test "$smth" = "1"; then
echo "Top process"
else
parents $sth
fi
}
read -p "Enter PID:" upid
parents $upid
when i run the script i get the error:
error: list of process IDs must follow -p
I have no idea what im doing wrong.
Upvotes: 0
Views: 127
Reputation: 4688
There are two mistakes in your script:
parents
with variable $sth
instead of $smth
ps -o ppid= -p "$1"
contains space characters which makes your test fail. Change the quoted "$smth"
in the test to $smth
.function parents(){
smth=$(ps -o ppid= -p "$1")
echo $smth
if test $smth = "1"; then
echo "Top process"
else
parents $smth
fi
}
Upvotes: 2