What's is the most efficient way to get process id of process by name using c++ code. I know, I can execute ps -a | grep "proces-name" to do it , is there better way to do it.
            Asked
            
        
        
            Active
            
        
            Viewed 52 times
        
    0
            
            
        - 
                    You say "cleanest" and "better", but you forget to say how to measure or compare solutions. – j6t Mar 11 '22 at 09:15
- 
                    @j6t It should most efficient and safe way , I'll edit the question. – CleanCoder540 Mar 11 '22 at 09:20
- 
                    1@AlanBirtles Here, the problem is to find the pid from the name, not the inverse! – Damien Mar 11 '22 at 09:21
- 
                    I have used `top -b -n1` for a long time, but I don't know if it is *better*. Using `pgrep`in an option too. – Damien Mar 11 '22 at 09:26
