[C] Process pid by name

Hi

I use linux OS.
I've already written a function that allow me to get the process name by pid. (searching in /proc). Now I'd like to perform the inverse task.I mean get the process pid by its name.

I could write a function that search in every folder in /proc for the process name, but i think that should be another solution. Something like include a kernel structure that keep information on the active process.

Can you suggest me another way? or some references where i can study?

Thx

D.

You still need to read the process info from /proc.

If you want to see how others have done it, look at the source code for the procps package, especially pgrep.c and readproc.c.

More than one process can have the same name, its always best to refer to them by their guaranteed-unique PID if at all possible.