Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-14-2010, 02:50 AM   #16
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,565

Rep: Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425

Doesn't make ANY difference; in *nix a process is a process (unless its a thread).
If 'ps -ef|grep <name> ' doesn't show the process, it means its not running anymore, even if it appeared(!) to start ok.
Try running it in the foreground ie sans '&' and see what happens.
Old 05-16-2010, 11:14 PM   #17
Registered: Sep 2009
Posts: 684

Original Poster
Blog Entries: 2

Rep: Reputation: 37
Originally Posted by alli_yas View Post

Yes - you're quite right. When you run the script with the ampersand (&) at the end the script is run in the background in a sub-shell.

Here's how you see whether your script is running or not:

# echo $!
# ps -ef | grep 9261
root      9261  9150  0 07:37 pts/1    00:00:00 ./
root      9285  9150  0 07:39 pts/1    00:00:00 grep 9261
Basically, when you issue the echo$! it will show you your background process - and then you can use ps for that PID to be able to see the state of your process.

I suggest you read the bash man page which gives a bit of insight into this.

# echo $!

No process is getting shown in background but my script is still running.
The reason i m so confident that its running in the background is because it is creating a file in /tmp at an interval of 5 second .Even if i delete the file it get created again.

Here i m posting my script.
while [ true ]
sleep 5
IPAddress=`netstat -an | grep :80 | grep -vE '(|LISTEN)' | awk '{print $5}'| awk -F ":" '{print $4}'`

if [ ! -f /tmp/SiteMonitor.log ]
touch /tmp/SiteMonitor.log
echo "[INF]-[`date +%Y%m%d-%H:%M:%S`]File Doesn't Exist Therefore creating a new one." >> /tmp/SiteMonitor.log
if [ ! -z "$IPAddress" ]
echo "[INF]-[`date +%Y%m%d-%H:%M:%S`]IP address :::::              $IPAddress " >> /tmp/SiteMonitor.log
if [ ! -z "$IPAddress" ]
echo "[INF]-[`date +%Y%m%d-%H:%M:%S`]IP address :::::              $IPAddress " >> /tmp/SiteMonitor.log


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
starting this as a service. dkc_ace Linux - General 15 12-27-2004 10:31 PM
Won't Boot - Starting Printer Service - Starting CUPS jeansond Linux - Newbie 0 10-11-2004 07:39 PM
starting one service before the other in Rh jayakrishnan Linux - General 2 11-19-2003 01:32 AM
starting up a service Robin01 Linux - Newbie 3 08-31-2003 06:04 AM
httpd service not starting... F$CK!!! xgtr Slackware 1 08-20-2002 04:13 PM > Forums > Linux Forums > Linux - Newbie

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

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