LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How can I filter the output of grep to exclude certain cases? (https://www.linuxquestions.org/questions/linux-general-1/how-can-i-filter-the-output-of-grep-to-exclude-certain-cases-163251/)

QtCoder 03-28-2004 12:02 AM

How can I filter the output of grep to exclude certain cases?
 
Hello.

I am in the process of writing a little script to automate my use of 3d-desktop (a nifty little eye-candy app) :) The script involves checking to see if 3ddeskd is running. So, I test the condition with `ps -e | grep 3ddeskd'. However, ps -e (or any other combo of args like ax) will also echo defunct processes. 3d-desktop tends to zombify sometimes (I don't know why), so in my test condition in the script, the test passes if grep sees "3ddeskd <defunct>". This is not acceptible. The condition should only pass if 3ddeskd is actually running.

So, my questions are:

Can one remove a defunct process without killing its parent? (this would be useful in many situations). If not, how could I filter the output of `ps -e | grep 3ddeskd' to include only the running 3ddeskd, if it exists?

I've tried using regex's in the argument to grep, but none have worked. Perhaps my bash regex skills are not very good.

Any help is appreciated.

Thanks

QtCoder 03-28-2004 12:05 AM

BTW,

I know I could spend a couple extra minutes writing another if-statement or two to deal with the defunct 3ddeskd, but I'm lazy. Actually, I think it's best to learn another way.


All times are GMT -5. The time now is 01:38 AM.