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!

Not Owner

Status
Not open for further replies.

crystal28

Programmer
Oct 23, 2002
108
US
I am trying to kill a process based on the code below
but it says i am not the owner.How do i kill it now.

#!/bin/csh -f
set a=1
foreach x (`ps -o ppid | cut -c2-8`)
if ($a > 1) then
echo $x
kill $x
endif
a =`expr $a + 1`
end
 
umm what is it you're trying to do?

cos currently it is nonsense ...
 
write sh or ksh NOT csh scripts. -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
jamisar,
this is gettin' repetitive and annoyin'...... vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
It would appear that your script is intended to attempt to kill *all* processes.

kill will only kill processes that belong the the current uid. If a process is owned by another user, it will not kill it.

The exception is root, root can kill any process. Now if you execute that script as root, you will crash your system in a hurry.
 
umm ... not quite ... it is written incorrectly and returns the PPID without the first character.

so a PPID of 55234 is returned as 5234 ... which probably isn't owned by you ...

if you have a PPID of 51 and you were root ... and especially if you tried the infamous 'kill -9' which i'm sure jamisar will tell you you should never do ;P then you might have a little problem with your machine :)

which leads me to the question:
&quot;what is it you're trying to do?&quot;
 
Ok guys.I think its the worst criticism ive ever got so far but i understand it might be deserving too.Anyway here is what i am trying to do.I am trying to kill all the processes that belongs to my user id.Please send me the whole code with the loop and variable declaration cause i am not familiar with unix at all.
 
It's theoretically possible, but such a script may not work properly all of the time.

If you have a script that goes through the process list killing all processes owned by the current user, eventually it will get to the process that is doing the killing, suicide, and thus not go any further, possibly leaving some other processes behind.
 
Thanks Chapter11,yes ur right it does suicide and stop the process and kills itself.But somehow i have to do this.Meanwhile i tried this command
ps -ef | grep $USER which returns the processes of the current user.This returns 2 columns of Process ids like below

kganesan 3116 3114 0 08:39:50 pts/6 0:01 -csh
kganesan 3317 3116 0 09:26:48 pts/6 0:00 grep kganesan

among which one is the process id.How do i find out which one of them is the process id.Please let me know.

Thanks a lot and any suggestion from anyone is appreciated.
 
The shell variable $$ stores the PID of the current process. In your script, ignore this PID and kill all the others.

Greg.
 
Thanks Greg,i think u were mentioning $x in my script and not $$ as there is no variable $$.How to ignore it, u mean skip it?
 
It won't be quite that easy. If you just filter out one process, you may still kill a parent or child of your script.

Try this ksh snippet:

[tt]MYTTY=`tty | cut -b 6-`
# you may need to adjust the cut values, you want MYTTY to look like &quot;pts/17&quot;

# assuming the current userid is stored in ${USER}:

ps -ef | grep ${USER} | grep -v ${MYTTY} | while read OWNER PID MISC
#^ Get all processes
# ^ just look at mine
# ^ filter out my processes attached to my current terminal
do
kill ${PID} # or -9 it if you like
done
 
Thanks Chapter11 i will try that out,i am working in CSH so i will convert it into that and do it.Will let u all know if this one works.But the bottomline is i am executing a FTP process and once its done i am killing the processes which is what i need to do.But the complication lies in killing all the proceses in the loop and as u said its not easy and it does hang while doing it.
 
Perhaps you could post the script that's starting all of this off? It shouldn't be necessary to write suicide scripts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top