script to get child process for a process

!/bin/sh

pid=$(ps -Aj | grep MSTRSvr | grep -v grep | awk '{print $1}')
sid=$(ps -Aj | grep MSTRSvr | grep -v grep | awk '{print $3}')
ps -s "$sid"

I am not able to get the desired output it says process list error
if i use watch ps -s "$sid" it considers only the first session id

Run in shell the 2 lines and paste output from echo $sid and echo $pid. Lets see what you get.

Something like this seems to work for me, fine (on Ubuntu). Perhaps, if you can provide more details as to your OS and a sample output, I may be able to help you better.

the problem is i am getting two pid's when i am pass it to ps -s it is not able to parse both of them .

Again, a sample output from each of the commands would have helped. Seems like you have multiple instances of MSTRSvr. If the intent is to get the pid for one of them, try:

| head -1

before the

| awk '{print $3}')

I figured it out as we need to count only one instance....thank you every one

---------- Post updated at 05:53 PM ---------- Previous update was at 05:52 PM ----------

ps -s 22345 | grep -v grep | awk '{print $1}'
output

PID
22345
28634
28641
28664
28666
28667

i need output as 22345,28634,..... is it possible i dont mind even i get it from a file