LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash: make ps silent (run in background) (https://www.linuxquestions.org/questions/programming-9/bash-make-ps-silent-run-in-background-4175436090/)

fatalerror0x00 11-07-2012 09:49 AM

bash: make ps silent (run in background)
 
I just need to get the command ps to run silently in the background. I can get it to run in the background but if I do it screws up results and displays something like a process id when I do) I need it to run in the background or even maybe hide it's output to see if it finds anything or not. I don't need to see if it's finds anything cause I just want a command to not run or well my script to not run if the process or another process of the same nature is running. example I don't want the script to run if my server shutdown or restart proocess is running (I will be using this in my restart, stop, and start codes) this will prevent rerunning them by accident

I have tried:

ps aux | grep -v grep | egrep 'stopphantasycraft' &
(ps aux | grep -v grep | egrep 'stopphantasycraft') &

both give some sort of result and then don't reset the command line and i press enter and it continues to give another result it's worse then just running it in the foreground and i don't know how to get it to work. Anyone got some alternatives? Thanks

schneidz 11-07-2012 09:52 AM

not really sure from your description what you are after but the standard in unix would be to append & at the end of your command to background it.

also check out bg and fg commands.

colucix 11-07-2012 10:00 AM

Quote:

Originally Posted by fatalerror0x00 (Post 4824209)
example I don't want the script to run if my server shutdown or restart proocess is running (I will be using this in my restart, stop, and start codes) this will prevent rerunning them by accident

Why not simply something like this at the beginning of the script?
Code:

ps -C stopphantasycraft > /dev/null && exit
The output of the ps command is redirected to /dev/null, but its exit status is still evaluated. Anyway, as schneidz, I'm not sure about your exact requirement. Please, can you elaborate? Thank you.

schneidz 11-07-2012 10:02 AM

also, much of what you need mite be possible by storing the pid ($!) in a variable or pid.file.

fatalerror0x00 11-07-2012 10:08 AM

& doesn't seem to work
 
I will try and figure out bg when I get home from work but thought that was the same thing as & just more of an at the time thing and bg for processes already running? The thing is for ps just & with my code DOESN'T give the desired results it DOESN'T run in the background it actually kinda runs in the forground and with more lines of some sorta output and exit code 3 times (1 time after each time you press enter) Thats not running in the background to me :P So I need a way to run ps in the background successfully thats it plain and simple :P if you can get it to run in the background in any way with no output then I really am glad to hear that and hope you can enlighten me :) cause even ps & doesn't run in the background. I know this program is about output but still I need it silenced.

seems this thread is popular :P i type that and got 2 more results :) Hang on guys trying this out.

fatalerror0x00 11-07-2012 10:13 AM

Code:

I'm not sure about your exact requirement. Please, can you elaborate? Thank you.
I have no idea how to make myself clearer other than a plain I need output of ps to be silenced. That's IT :)

unSpawn 11-07-2012 10:14 AM

Quote:

Originally Posted by fatalerror0x00 (Post 4824209)
Anyone got some alternatives?

Use pgrep instead to check:
Code:

pgrep stopphantasycraft >/dev/null 2>&1; RETVAL=$?
then use the exit value for whatever you need to do.

fatalerror0x00 11-07-2012 10:20 AM

so moving the output of ps to /dev/null was a great idea that verywell works :) thank you :)

why use pgrep? I mean idk why egrep it's just what I found so just curious thank you


All times are GMT -5. The time now is 10:48 PM.