I am trying to check if a process is running. If it is running I want a return value of 'OK' and if not a return value of 'Not OK'. I can only use 'ps' without any other arguments attached (eg. ps -ef) if thats the correct term. The code I have is:
if ps | grep file; then echo 'OK'; else echo 'NO'; fi
The problem with this is that it does not search for the exact process and always returns 'OK', I don't want all the information to appear I just want to know if the file exists or not.
Most people have at least heard of “Ctrl+Alt+Delete”. This key combination allows the user to open Windows Task Manager. Task Manager is a utility within the Windows operating system that shows information such as running processes, computer performance, background services, and more.
Your code always returns 'OK', because grep finds itself in the process list ('grep file' contains the word 'file'). A fix would be to do a `grep -e [f]ile' (-e for regular expression), which doesn't find itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With