Originally posted by: wdephoff
Hi,
here a "quick and dirty" Kornshell-Script (running under Linux)
I have a file (apps_pid.txt) with Process-IDs:
3075 3175 2955
The output for Process 3075 is:
ps -ef |grep 3075 wolfgang 3075 3073 0 10:51 ? 00:00:00 /usr/sbin/mysqld --defaults-file=/home/wolfgang/.local/share/akonadi
//mysql.conf --datadir=/home/wolfgang/.local/share/akonadi/db_data/ --socket=/home/wolfgang/.local/share/akonadi/socket-tsmsrv1/mysql.socket
for Process 3175 (note the multiple lines with PPID):
ps -ef |grep 3175 tsminst1 3175 3134 5 10:52 ? 00:00:54 db2sysc 0 root 3177 3175 0 10:52 ? 00:00:00 db2ckpwd 0 root 3180 3175 0 10:52 ? 00:00:00 db2ckpwd 0 root 3181 3175 0 10:52 ? 00:00:00 db2ckpwd 0 tsminst1 3188 3175 0 10:52 ? 00:00:01 db2vend (PD Vendor Process - 1)
and for process 2955:
ps -ef |grep 2955 root 2955 1 0 10:51 ? 00:00:00 /opt/tivoli/tsm/db2/bin/db2fmcd
here my script (get_ps.ksh):
#/usr/bin/ksh cat apps_pid.txt|
while read line
do set $line pid=$1 ps -ef |grep -v grep|grep $pid|
while read line1 # loop thru all line with the pid
do set $line1 # get user and process id as field 1 and 2 user=$1 xpid=$2
if [
"$xpid" -eq
"$pid" ] # filter the lines whith PID as field 2 then shift 7 # shift the hole line to the left, to get the Process-description proc=$* echo
"PID: $pid - User: $user" echo
"Proc: $proc" echo
"\n"
else
continue fi done done
and the Output:
./get_ps.ksh PID: 3075 - User: wolfgang Proc: /usr/sbin/mysqld --defaults-file=/home/wolfgang/.local/share/akonadi
//mysql.conf --datadir=/home/wolfgang/.local/share/akonadi/db_data/ --socket=/home/wolfgang/.local/share/akonadi/socket-tsmsrv1/mysql.socket PID: 3175 - User: tsminst1 Proc: db2sysc 0 PID: 2955 - User: root Proc: /opt/tivoli/tsm/db2/bin/db2fmcd
I hope this helps you.
regards
Wolfgang