mahmood
mahmood

Reputation: 24705

finding the process numbers of a multithread application

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

Answers (2)

oliv
oliv

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

sozkul
sozkul

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

Related Questions