LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-07-2012, 09:49 AM   #1
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Rep: Reputation: 0
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

Last edited by fatalerror0x00; 11-07-2012 at 09:51 AM.
 
Old 11-07-2012, 09:52 AM   #2
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,956

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
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.
 
Old 11-07-2012, 10:00 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,489

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Quote:
Originally Posted by fatalerror0x00 View Post
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.
 
Old 11-07-2012, 10:02 AM   #4
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,956

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
also, much of what you need mite be possible by storing the pid ($!) in a variable or pid.file.
 
Old 11-07-2012, 10:08 AM   #5
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
& 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.

Last edited by fatalerror0x00; 11-07-2012 at 10:09 AM. Reason: more post
 
Old 11-07-2012, 10:13 AM   #6
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
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
 
Old 11-07-2012, 10:14 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,140
Blog Entries: 54

Rep: Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791
Quote:
Originally Posted by fatalerror0x00 View Post
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.
 
Old 11-07-2012, 10:20 AM   #8
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
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

Last edited by fatalerror0x00; 11-07-2012 at 10:24 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command or function in C to make the process run in background sowpra Linux - Newbie 4 05-02-2012 12:56 AM
rtorrent. how to make it run in the background?? nass Linux - Software 4 08-13-2011 07:50 AM
[SOLVED] How does '&' make a process run in background ? TheIndependentAquarius Programming 22 12-22-2009 10:58 AM
Make SCP run in background? Moonman Linux - Software 3 11-29-2007 07:46 AM
How to run a bash command in the background from perl script professorfrink Programming 3 11-13-2003 03:02 PM


All times are GMT -5. The time now is 09:24 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration