ps returning more process ids


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ps returning more process ids
# 1  
Old 10-11-2013
ps returning more process ids

Please help me with this question

I have a tantan.sh under /home/mydir which is a caller to another script "tantan.sh" under /home/anotherdir
-----------------------------------------------------------
/home/mydir/tantan.sh
------------------------------------------------------------
Code:
#!/bin/sh

echo "caller script
/home/anotherdir/tantan.sh
exit 0

-----------------------------------------------------------
/home/anotherdir/tantan.sh
-----------------------------------------------------------
Code:
#!/bin/sh
echo "actual script"
 ps -ef |grep tantan.sh | grep -v grep|awk '{print $2}'

 for PID in `ps -ef | grep "tantan.sh" | grep -v "grep" |awk '{print $2}'`
                do
                        echo $PID
                done

This always echos 3 PIDs and not two. My requirement is to see, that if there are two or more tantan.sh process initiated, then exit. Only one tantan.sh must be there at any time, parellel processing is not supported.

I was thinking to go this way, if there is any other process other than the currentPID and parent PID, then exit, but since the ps command returns three PIDs, I am not able to get a solution, please advice.

Last edited by Franklin52; 10-11-2013 at 04:04 AM.. Reason: Please use code tags
# 2  
Old 10-11-2013
Is the script detecting itself as a running process?
# 3  
Old 10-11-2013
What are you trying to achieve ?
Why are you using 2 scripts instead of just 1 ?
# 4  
Old 10-11-2013
I only get two PIDs outputted, so something else is going on.

What is the full output of:
Code:
# ps -ef | grep tantan.sh | grep -v grep

# 5  
Old 10-11-2013
Just to save the last "grep -v grep" pipe ...
Code:
# ps -ef | grep [t]antan.sh

# 6  
Old 10-12-2013
Or just use this to get the pid
Code:
pidof tantan.sh

# 7  
Old 10-12-2013
Code:
ps -ef | grep -w "tantan\.sh" | grep -vw "$$" | grep -vw "grep"


Last edited by MadeInGermany; 10-12-2013 at 06:30 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List out Process ids restarted today

Hi, I need to list out the processes which are started/restarted today in my Solaris box. If not possible need to convert the process uptime in minutes or seconds and compare it with a configurable value to list out those process ids for further processing in my scripting. Can any one guide... (7 Replies)
Discussion started by: ananan
7 Replies

2. Shell Programming and Scripting

Search process ids

Hi, I have four tomcat instances named PNK, PNK1, PNK2, PNK3. All are running on the same server. To kill tomcat instance I usually do below for PNK1,PNK2,PNK3 kill -9 `ps -ef|grep tomcat|grep PNK1|grep -v grep|awk '{print $2}'` But the above command does not work for PNK. Can some... (7 Replies)
Discussion started by: lpprasad321
7 Replies

3. Red Hat

RHEL6 : Remote process exited without returning status

Hi All, I am using RHEL 6 linux in my lab server and I am new to RHEL6 features. lab1:root> uname -a Linux lab1 2.6.32-358.18.1.el6.x86_64 #1 SMP Fri Aug 2 17:04:38 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux I am facing a peculiar issue in my lab machine. When I connected via Opsware Global... (0 Replies)
Discussion started by: go2suresh1979
0 Replies

4. Shell Programming and Scripting

Script for to kill the process Ids when restarting the unix server

Hi, I need a script to kill the process Ids for the user ABC. I prepared the following script after that while logging with user therough script i am not sure how to pass the user name and password.Can ou modify the script and help me out. #!/bin/bash for filesize in $(ls -ltr | grep... (4 Replies)
Discussion started by: victory
4 Replies

5. AIX

Process ids consuming huge resources ?

Hi All what is the command to check process ids , which are running from long time and which are consuming more cpu? Also how to check, what a particular PID is running what For Ex: i have a pid :3223722 which is running since from long time, if i want to check what is this... (1 Reply)
Discussion started by: sidharthmellam
1 Replies

6. UNIX for Dummies Questions & Answers

Scripting - process and user ids...Help please

Hello all: Working on a job I was asked get a simple script to perform the following task and would like to ask for some help. I'm looking forward to learning more and diving deeper into the World of Open Source servers. I need a script for a Unix server, using as few lines as possible, that... (4 Replies)
Discussion started by: moahten
4 Replies

7. Shell Programming and Scripting

script to loop all process ids and take pmap

Hi all, I need a script that will loop around all the current processes and take a pmap -x <process id> and output each pmap to a separate file. Would anyone have a quick command to do this? (2 Replies)
Discussion started by: borderblaster
2 Replies

8. UNIX for Advanced & Expert Users

Problem to track process IDs in HP-UX machine

Hello All, I need to track the exact process ID related to a particular application running on HP-UX machine. i.e. the exact functionality of fuser unix command. fuser application.log // It gives the exact process ID for application.log Since there is no provision for 'fuser' in HP-UX... (13 Replies)
Discussion started by: abhishek0071
13 Replies

9. UNIX for Advanced & Expert Users

ps | grep command not returning existing process

Hello all, I develop an ERP application that runs on a number of *nix flavors. This application had been around for quite a number of years. As part of the application launch, we do a check for a background process using the following command: ps -ef | grep -v grep | grep mi\/ba | grep... (6 Replies)
Discussion started by: jlitzie
6 Replies

10. Programming

List of Thread IDs of a process

Hello, Can some one tell how to read the thread IDs of the current process in Sun Solaris. Any help will be appreciated. regards, Murali (0 Replies)
Discussion started by: hmurali
0 Replies
Login or Register to Ask a Question

Featured Tech Videos