long process listing with /usr/ucb/ps weird behaves


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting long process listing with /usr/ucb/ps weird behaves
# 1  
Old 06-07-2009
Java long process listing with /usr/ucb/ps weird behaves

hello

I am trying to run the following script to get the my-progam pid:

#!/bin/ksh
tt=`/usr/ucb/ps| grep -i $1| grep -v grep | awk '{print $2}'`
echo $tt

When I run the script I get the more PIDs

$./test.sh my-program
12033 15033 15034

Actually my-program's PID is 12033....I am not sure why I am I getting the other two PIDs. These other two PIDs change everytime I run the script.

But when I then the script without a command line argument, it gives me only one PID.

Can anyone help me out...as I need to use similar script to get the PID as a result to some program?
# 2  
Old 06-07-2009
Quote:
Originally Posted by sreeniatbp
hello

I am trying to run the following script to get the my-progam pid:

When you post code, please wrap it in [code] tags.
Quote:
Code:
#!/bin/ksh
tt=`/usr/ucb/ps| grep -i $1| grep -v grep | awk '{print $2}'`
echo $tt


Why not:

Code:
tt=$$

If you want the PID of the calling program, use $PPID.
Quote:
When I run the script I get the more PIDs

$./test.sh my-program
12033 15033 15034

Actually my-program's PID is 12033....I am not sure why I am I getting the other two PIDs. These other two PIDs change everytime I run the script.

Have you looked at the output of ps?
Quote:
But when I then the script without a command line argument, it gives me only one PID.

Can anyone help me out...as I need to use similar script to get the PID as a result to some program?
# 3  
Old 06-08-2009
[code]
#!/bin/ksh

for i in `/usr/ucb/ps -wwaux | grep $1 | grep -v grep |awk '{print $2}'`
do
echo $i
#kill -9 $i
done


When I run this I get two different PIDs, one for 116694 and 17002. this happens when i run the command as

$/usr/ucb/ps -wwwaux | grep myServices-Primary
tradmin 16694 0.0 1.4443536220216 ? S 12:41:05 2:18 /opt/barc/bin/engine --pid --run /opt/barc/domain/SOAMP_NTA_DEV//myServices-Primary/myServices-Primary.xyc --innerProcess

$./mytest myservice-primary

I couldnt still manage to still kill the process...as I only wnat to kill this process.
# 4  
Old 06-08-2009
Quote:
Originally Posted by sreeniatbp
Code:
#!/bin/ksh

for i in `/usr/ucb/ps -wwaux | grep $1 | grep -v grep |awk '{print $2}'`


Don't use for; pipe the output into a loop.

Why are you using -ww when all you want is the second field?

Can you choose the fields you want with your version of ps (-o option)?
Quote:
Code:
do
echo $i
#kill -9 $i
done


What output does this produce:

Code:
/usr/ucb/ps -aux | grep $1 | grep -v grep |
while read owner pid ppid
do
  printf "PID = %d\n" "$pid"
done

# 5  
Old 06-09-2009
There are two threads going for this topic:

https://www.unix.com/shell-programmin...l-process.html

The answer to the original question is that when you call the script with the parameter, the call to the script appears in the "ps" list complete with the parameter. You need to "grep -v" the script name from the "ps" list.

For cfajohnson, I believe that $1 is the text to be searched for in the "ps" display (not the process ID). I guess we need "/usr/ucb/ps -wwaux" to see enough of the original command line to find the string with "grep".
# 6  
Old 06-09-2009
Quote:
Originally Posted by methyl
There are two threads going for this topic:

https://www.unix.com/shell-programmin...l-process.html

The answer to the original question is that when you call the script with the parameter, the call to the script appears in the "ps" list complete with the parameter. You need to "grep -v" the script name from the "ps" list.

'grep -v grep' should have the same effect.
Quote:

For cfajohnson, I believe that $1 is the text to be searched for in the "ps" display (not the process ID). I guess we need "/usr/ucb/ps -wwaux" to see enough of the original command line to find the string with "grep".

All versions of ps that I've seen will always print the command with or without -ww (unless it's suppressed with the -o option).
# 7  
Old 06-10-2009
The shebang at the start of the script starts a new shell and the command line appears in memory.

Consider this example:

Code:
#!/bin/ksh
# myscript
PARAM="$1"
ps -ef|grep "${PARAM}"

./myscript myparameter
root 25874 25872  1 11:55:21 pts/ta    0:00 grep myparameter
root 25872 22814  2 11:55:21 pts/ta    0:00 /bin/ksh ./myscript myparameter

I've seen many unixes with "ps" supplied which does not display the full command line without additional parameters or invoking an alternative "ps".
e.g. HP-UX, old SCO and old SUNOS.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Listing the long groupnames

Hello, When listing the file systems (using ls -ltr) , if the group names are longer the group name is getting truncated. Can someone help with the script which would display the truncated group name? I appreciate if someone could help in this regard. (1 Reply)
Discussion started by: mike12
1 Replies

2. UNIX for Advanced & Expert Users

how can i use /usr/ucb/ps to give the full user

Hi, on solaris I need the full ps output, and process this. With /usr/ucb/ps auxwww I get the output as wanted, but the user is cut off to 8 long. With ps -o ruser I can get the full username, but I do not have the full output. Is it possible to get long output, with the full username? ... (1 Reply)
Discussion started by: dimpie
1 Replies

3. Solaris

How do I link ld in /usr/ucb/ to /usr/ccs/bin?

Hi all, below is the problem details: ora10g@CNORACLE1>which ld /usr/ucb/ld ora10g@CNORACLE1>cd /usr/ccs/bin ora10g@CNORACLE1>ln -s /usr/ucb/ld ld ln: cannot create ld: File exists ora10g@CNORACLE1> how to link it to /usr/ccs/bin? (6 Replies)
Discussion started by: SmartAntz
6 Replies

4. UNIX for Advanced & Expert Users

/usr/ucb/ps -auxwll

Hei, When I run the /usr/ucb/ps -auxwll with any other user except root I get nothing (Solaris 10 in global). Is a way to get the same resualt as root with my user. tnx Mehrdad (0 Replies)
Discussion started by: mehrdad68
0 Replies

5. Shell Programming and Scripting

problem get the value of /usr/ucb/ps -guxww

Hello all im trying to get the value of: /usr/ucb/ps -guxww | grep Tomcat | grep $USER | grep -v grepinto variable , im using csh . like this : set PS="/usr/ucb/ps -guxww" set isTomcat = `cat $PS | grep Tomcat | grep $USER | grep -v grep` but im keep geting this error: cat: cannot open... (4 Replies)
Discussion started by: umen
4 Replies

6. UNIX for Dummies Questions & Answers

ksh: /usr/bin/ls: arg list too long

I am using IBM AIX unix version 4.3.3.0. In a directory there are many files with different patterns. When I am trying to execute the command, ls -l with the file pattern, which have fewer files it gives the desired result. However when I am trying to execute the same command for file pattern,... (2 Replies)
Discussion started by: jitindrabappa
2 Replies

7. Solaris

/usr/bin/ps -p equivalent in ucb version

Hi, Is there an option in /usr/ucb/ps version to get a selected list of processes like in /usr/bin/ps -p"1 3 5" option? Thanks, Fredy (7 Replies)
Discussion started by: fredy
7 Replies

8. Shell Programming and Scripting

date=`/usr/ucb/expr $date1 - 1`

Hi I need to subtract one day from date1=`/bin/date +%d` So I used date=`/usr/ucb/expr $date1 - 1` The only thing is if date1 is a single digit like 08, date will be 8 instead of 08. How can I avoid losing 0? Thanks for all your help!!! (4 Replies)
Discussion started by: whatisthis
4 Replies

9. Solaris

solaris 2.5.1 /usr/ucb/ps truncation problems

we aheva couple of old sun OS boxes, that we are trying to parse /usr/ucb/ps output. However it seems that something is occuring that is causeing th output of "/usr/ucb/ps -auxwww" to cut short the process name, whereas "ps -eaf" can display the entire process name. It will work for a while... (2 Replies)
Discussion started by: adralph
2 Replies

10. UNIX for Dummies Questions & Answers

long listing of files up to a given date

Hi I would like to a long list of files up to a given date. I've tried: ls -al > filelist but this command gives me all the files. I've also have tried the find command: find . -mtime -10 -type f -print > filelist This gives me information on active file within the past 10 days and... (2 Replies)
Discussion started by: rlh
2 Replies
Login or Register to Ask a Question