Loading...

Retrieve process id from ps

Example process without the grep command

tan@omega:~/bin> ps -Af | grep '[f]ile-watchdog.sh start'
tan 40502 1 0 12:23 pts/1 00:00:00 bash ./file-watchdog.sh start
tan 40504 40502 0 12:23 pts/1 00:00:00 bash ./file-watchdog.sh start

Show only process id

tan@omega:~/bin> ps -Af | grep '[f]ile-watchdog.sh start' | awk '{ print $2}'
40502
40504

Show first process

tan@omega:~/bin> ps -Af | grep '[f]ile-watchdog.sh start' | awk '{ print $2}' | head -n 1
40502

Show last process

tan@omega:~/bin> ps -Af | grep '[f]ile-watchdog.sh start' | awk '{ print $2}' | tail -n 1
40504