LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-14-2010, 02:50 AM   #16
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325

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
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by alli_yas View Post
Hi

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:

Code:
# echo $!
9261
# ps -ef | grep 9261
root      9261  9150  0 07:37 pts/1    00:00:00 ./myscript.sh
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.

Cheers
Yas
# 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.
Code:
while [ true ]
do
sleep 5
IPAddress=`netstat -an | grep :80 | grep -vE '(127.0.0.1|LISTEN)' | awk '{print $5}'| awk -F ":" '{print $4}'`

if [ ! -f /tmp/SiteMonitor.log ]
then
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" ]
then
echo "[INF]-[`date +%Y%m%d-%H:%M:%S`]IP address :::::              $IPAddress " >> /tmp/SiteMonitor.log
fi
else
if [ ! -z "$IPAddress" ]
then
echo "[INF]-[`date +%Y%m%d-%H:%M:%S`]IP address :::::              $IPAddress " >> /tmp/SiteMonitor.log
fi
fi
done
 
  


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
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


All times are GMT -5. The time now is 04:53 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration