I have a process which is getting launched by two different processes(one is by init and other by lxc container)
I am trying to get the pids of the process using process name by command $(pidof $PROCESS_NAME)
,
which works fine. The command gives 2 pid values , but when i try to print the individual values
using a=(${process_pids[0]})
and b=(${process_pids[1]})
only first command yields the first value, second one prints empty.
Also the length is showing as 1 despite we have two elements in the array process_pids
On the other way if we enable numbers_normal=(1234 5678)
instead of process_pids=$(pidof $PROCESS_NAME)
, though echo "pids = $numbers_normal"
print only one value, the indexing is working fine.
What is the problem with the statement process_pids=$(pidof $PROCESS_NAME)
and how to correct it.
#!/bin/sh
PROCESS_NAME=process1
process_pids=$(pidof $PROCESS_NAME)
#numbers_normal=(1234 5678)
echo "pids = $process_pids"
a=( ${process_pids[0]} )
b=( ${process_pids[1]} )
echo "0th = $a"
echo "1st = $b"
# lengths are showing as 1, but the number of items are 2
echo "length = ${#process_pids[*]}"
echo "L = ${#process_pids[@]}"
for i in ${process_pids[@]}; do
echo "pid $i parent is $(ps -o ppid= -p $i)"
done