hervasiop12345

psancestros

Aug 16th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.59 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #Description: Dado un PID vĂ¡lido muestra la lista de PIDs desde el dado hasta el PID 0
  4. #
  5. #Author:jMa
  6. #
  7.  
  8. if [ \( $# -eq 1 \) ] && [ \( `ps aux | tr -s " " | cut -d " " -f 2 | grep $1 | wc -c` -gt 0 \) ]
  9. then
  10.   pid=$1
  11.   echo -n "PID $1-->"
  12.   if [ "$1" -eq "0" ]
  13.   then
  14.     echo
  15.   fi
  16.   while [ "$pid" != "0" ]
  17.   do    
  18.     ppid=`ps -l $pid | tr -s " " | cut -d " " -f5 | tail -1`    
  19.     if [ "$ppid" != "0" ]
  20.     then
  21.       echo -n "$ppid-->"
  22.     else
  23.       echo  "$ppid"
  24.     fi
  25.     pid=$ppid
  26.   done
  27. else
  28.   echo -e "Error\nSintax: ./psacestros PIDExistente"
  29. fi
Advertisement
Add Comment
Please, Sign In to add comment