LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-29-2015, 07:44 AM   #1
avi2004
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Rep: Reputation: Disabled
Lightbulb Starting a script creates two similar process for the script


I have a script that is used to start a application process.Argument "start" has to be passed to this script to start the process.

When I run the script there are two process created for the same :

root 22760 22682 3 13:32 pts/2 00:00:00 <scriptname> start
root 22850 22760 0 13:32 pts/2 00:00:00 <scriptname> start

Not able to understand why there are two processes .Also one of them is a child of another.
This is failing a check in the script which checks if there is already a running script (check number of process of the script >1)

Any ideas are welcome .
 
Old 06-29-2015, 09:25 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
How are you checking if there is a running script?
Can you paste your code here?
 
Old 06-29-2015, 09:35 AM   #3
avi2004
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
How are you checking if there is a running script?

var3=`ps -ef|grep "<scriptname> start"|grep -v grep|awk '{print $2}'`
cnt=$(ps -ef | grep "<scriptname> start" | grep -vc grep)
if [[ "${cnt}" -ge 2 ]]
then
echo "The process is already running..... : $var3"
exit 1
fi

So the script is exiting as we can see two processes running when script is executed.
 
Old 07-01-2015, 01:30 AM   #4
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Are you using this segment of code in same script which is running twice?
If same script is running two or mor times and you use this code in another script and run it, it will show you the message that the script is already running.

When you are passing argument start, in that segment of code, make sure it should not same script another time.
If you kill one of the script, are both script killed? You can try this after clicking child process.
 
Old 07-01-2015, 03:25 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,847

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
you can also try to use pgrep scriptname
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My First PHP script - MemoryReporter - Analyze Process with single script nijinashok00 Linux - Server 3 09-25-2013 02:50 AM
Bash script creates blank file name snowman81 Programming 9 03-02-2008 10:37 PM
kill the process invoked from a shell script, when the script is killed kskkumar Linux - Software 8 05-23-2007 11:29 AM
Bash script hangs upon starting another script in the background masea2 Linux - Software 4 11-13-2006 05:18 AM
automatically starting process in Fedora Core 2 by using script falkesgaard Programming 1 07-29-2004 10:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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
Open Source Consulting | Domain Registration