15 lines
274 B
Bash
15 lines
274 B
Bash
|
|
#!/bin/bash
|
||
|
|
ps_parents ()
|
||
|
|
{
|
||
|
|
if [ "$#" -ne 1 ]; then
|
||
|
|
echo "Usage: $0 <pid>";
|
||
|
|
return 1;
|
||
|
|
fi;
|
||
|
|
pid=$1;
|
||
|
|
while [ "$pid" -ne 1 ]; do
|
||
|
|
ps -p $pid -o pid=,ppid=,cmd=;
|
||
|
|
pid=$(ps -p $pid -o ppid= --no-headers);
|
||
|
|
done
|
||
|
|
}
|
||
|
|
ps_parents "$@"
|