Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting around truncated "ps"

Tags:

solaris

I'm trying to write a script that will find a particular process based on a keyword, extract the PID, then kill it using the found PID.

The problem I'm having in Solaris is that, because the "ps" results are truncated, the search based on the keyword won't work because the keyword is part of the section (past 80 characters) that is truncated.

I read that you can use "/usr/ucb/ps awwx" to get something more than 80 characters, but as of Solaris 10, this needs to be run from root, and I can't avoid that restriction in my script.

Does anyone have any suggestions for getting that PID? The first 80 characters are too generic to search for (part of a java command).

Thanks.

like image 397
julian Avatar asked Feb 03 '11 22:02

julian


3 Answers

ps "whatever your options" | cat

Works for me; trying to fool ps that stdout is not a tty.

like image 85
XYZ Avatar answered Oct 19 '22 03:10

XYZ


This works for me, at least on Joyent SmartMachine:

/usr/ucb/ps auxwwww
like image 24
Aaron Avatar answered Oct 19 '22 02:10

Aaron


You assumption about ps behavior is incorrect. Even while you aren't logged as root, "/usr/ucb/ps -ww" doesn't truncate arguments for processes you own, i.e. for processes you can kill which are the only one you are interested in.

$ cat /etc/release
                    Oracle Solaris 10 9/10 s10x_u9wos_14a X86
     Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
                            Assembled 11 August 2010
$ id
uid=1000(jlliagre) gid=1000(jlliagre)
$ /usr/ucb/ps | grep abc
  2035 pts/3    S  0:00 /bin/ksh ./abc aaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbb
$ /usr/ucb/ps -ww | grep abc
  2035 pts/3    S  0:00 /bin/ksh ./abc aaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccccccccccccccccccccccccccccccccc ddddddddddddddddddddddddddddddddddddddddddd
like image 24
jlliagre Avatar answered Oct 19 '22 03:10

jlliagre