0
108   ps --ppid $process | while read -r line ; do
109      #echo $line | awk '{print $1;}
110      child=$($line | awk '{print $1;}')
111      echo $child
113   done

Running this code gives me the following error:

line 111: 3405: command not found

But if I uncomment line 109 it prints the correct value without an error

techraf
  • 5,831
  • 10
  • 33
  • 51
shav017
  • 9
  • 2

2 Answers2

1

The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.

If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:

ps --ppid "$process" -o pid=

This would get the list of processes that has $process as their PPID, and for each output their PID.

Also related:

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
0

Fix it...

ps --ppid $process | while read -r line ; do
  child=$(echo $line | awk '{print $1}')
done
jas-
  • 858
  • 5
  • 8