Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exclude current running process from ps list

Status
Not open for further replies.

stackdump

Technical User
Sep 21, 2004
278
GB
Hi all,

I want to write a small script to kill processes matching a given input string. I use the code below but of course this also shows up on the ps list.

Code:
#!/bin/csh -f

set myname=`whoami`

if ($#argv == 1 ) then
    if (`/bin/uname` == "Linux") then
        set myid = `id -u $myname`
        kill -9 `ps -u $myname | grep -i $1 | grep -v grep | grep -v ps | grep -v tcsh | awk '{print $1}'`
    endif
endif

I have to put all the grep's in to mask out this process, is there some way of doing this without the current process lighting up?
 
You should only have to use one part of the string you wish to grep -v in order to exclude it from your listing.
 
But if I do;

ps -u `whoami` | grep -v example

I see a ps, tcsh and a grep process ID listed?

Is there a way to ignore the processes associated with the current command? rather than;

ps -u `whoami` | grep -v ps | grep -v tcsh | grep -v grep

which will mask out any other process using these strings?
 
eg:
ps -ef | grep [k]sh


"If you always do what you've always done, you will always be where you've always been."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top