Reputation: 24705
How can I retrieve the process numbers of a issued multithread application? I mean, I am looking for a bash script that after executing a command, puts the process numbers in a list. For example:
#!/bin/bash
./run_program -nt 4
# find the list of PIDs
Upvotes: 1
Views: 56
Reputation: 13249
I would use pgrep
for checking the process ids.
If you're only looking at child PID of the current process, you can use the -P
option:
pgrep -P $$
Upvotes: 2
Reputation: 675
Assuming run_program
creates same execute path in ps pid list.
ARRAY=($(ps -fe | grep run_program | grep -v grep | awk '{print $2}' ORS=' '))
and you can access in example
echo ${ARRAY[2]}
Upvotes: 1