The usual way would be to use pgrep
:
$ pgrep init
1
2215
6300
$ ps ax | grep init
1 ? Ss 6:41 /sbin/init
2215 ? Ss 1:54 init --user --restart --state-fd 26
6300 ? S 0:00 init --user --startup-event indicator-services-start
17522 pts/10 S+ 0:00 grep --color=auto init
Note that you might need to use other tricks with pgrep
as well, if you use it with watch
and -f
:
$ watch pgrep init -fa
Every 2.0s: pgrep init -fa
Wed Dec 3 19:19:47 2014
1 /sbin/init
2215 init --user --restart --state-fd 26
6300 init --user --startup-event indicator-services-start
18233 watch pgrep init -fa
18234 watch pgrep init -fa
18235 sh -c pgrep init -fa
$ watch pgrep [i]nit -fa
Every 2.0s: pgrep [i]nit -fa Wed Dec 3 19:20:42 2014
1 /sbin/init
2215 init --user --restart --state-fd 26
6300 init --user --startup-event indicator-services-start