KILLING Mac OS

broken image


Kill -TERM tells a process to shutdown (TERMinate) and gives the process the opportunity to do so cleanly. Kill -KILL (aka kill -9) is a shutdown that doesn't allow the process to shutdown cleanly. How do I find (and kill) processes that listen to/use my tcp ports? I'm on mac os x. Sometimes, after a crash or some bug, my rails app is locking port 3000. I can't find it using ps -ef. ⚠ Fairly Demanding: You'll need a recent Mac. System requirements: OS X 10.9.5, 2.2 Ghz Intel Core i3, 4 GB RAM, 10 GB HD space, NVIDIA Geforce 330M, ATI Radeon HD 3870, or Intel HD 3000 with 256 MB of Video Memory. Role-Playing: Medium: No: Wasteland 2: Director's Cut: Wasteland 2: Director's Cut.


Kill process by name instead of PID | 10 comments | Create New Account
Click here to return to the 'Kill process by name instead of PID' hint

Type 'kill ###'. Replace the '###' with the number from the PID Column you just located. For example: If you were trying to quit iTunes, and found iTunes to have PID number 3703, you would type 'kill 3703'. If the program does not respond to the 'kill' command, type 'sudo kill -9 ###', replacing ### with the PID number. Kill -TERM tells a process to shutdown (TERMinate) and gives the process the opportunity to do so cleanly. Kill -KILL (aka kill -9) is a shutdown that doesn't allow the process to shutdown cleanly.

The following comments are owned by whoever posted them. This site is not responsible for what they say.
This might be a too convenient way of doing things, actually. Anything that matches your text string will be killed, which is why I think it is 'too convenient'. For instance,
pkill ssh
will attempt to kill every process with the text string 'ssh' in it, including not only ssh-sessions, but also ssh daemons and your ssh-agent. Which is why this script should never be run as superuser (I could find a lot worse examples than with ssh above).. Personally, i prefer double checking processes before i kill them. Look them up with ps and kill them with kill, slightly inconvenient, but safe

yeah, gotta agree with kal, this is an extremely bad practice. one needs to know the potential effect of blindly running this kind of operation.

Killing Mac Os 11

Why not use the '-w' flag for grep to match on a whole word?

Killing mac os x
Type man killall for a revelation.

Mac Os Download

ditto

I found this command immediately after submitting this script. doh.

live and learn - we all do

**this is not a flame it's meant to be constructive critisim**
at the least you should not be matching things like ssh-agent if you choose ssh with this script. that is just wrong. sorry! because if you do that you can trigger all sorts of problems killing processes that you did not intend to kill..
this script is a duplication of functionality and while it is intersting and duplication of functionality is kinda what open source is all about this script is just dangerous!!!!
granted that the danger is minmal, esp if the script is not run as the superuser.. there is little you can do, but throwing around kill's arbitrarily will screw things up!
for example i have both inetd and xinetd running here for some reason??? anyone know why??? and if i ran your script with 'inetd' it would kill inetd && xinetd that's just wrong.. especially when there are better tools on the system that will do the job properly 'killall' ????
i'm not trying to be rude at all but.. at least do exact process name matching.

a modification for pidof to kill..
the default is to send a sighup but you can kill too
ie ./kill name sig
place this script somewhere and chmod it 755
it's the perl version so the matching is better!
the base for this code came from someone who submitted a perl version as a comment to my bash&tr&awk pidof script, i forget his name but just want to make people know it's not entirely my own. The piece puzzle mac os. but heavily modified.

#!/usr/bin/perl
$search=$ARGV[0];
if ($ARGV[1]) {$sig=$ARGV[1]; } else { $sig=1; }
@procs = `ps -cxa`;
for $proc (@procs ) {
if( $proc =~ /s+(d+)s+S+s+S+s+S+s+(S+)/ ) {
$pid = $1;
$name = $2;
if( $name =~ /^$search$/ ) {
kill $sig,$pid;
print '$pid ';
}
}
}
print 'n';

I read both this hint and the A bash script to kill a process hint, and even read parts of the post where some users said to use the 'killall' command. None worked for my case where the app name contained spaces in the name, like Internet Explorer.app. To make sure I am not nuts, try the above hints yourself because I would prefer a smaller bit of code then what I wrote below. Also it is in PHP, I was not cool enough to write it in a unix shell script.

Kill process by name instead of PID | 10 comments | Create New Account
Click here to return to the 'Kill process by name instead of PID' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
This might be a too convenient way of doing things, actually. Anything that matches your text string will be killed, which is why I think it is 'too convenient'. For instance,
pkill ssh
will attempt to kill every process with the text string 'ssh' in it, including not only ssh-sessions, but also ssh daemons and your ssh-agent. Which is why this script should never be run as superuser (I could find a lot worse examples than with ssh above).. Personally, i prefer double checking processes before i kill them. Look them up with ps and kill them with kill, slightly inconvenient, but safe

yeah, gotta agree with kal, this is an extremely bad practice. one needs to know the potential effect of blindly running this kind of operation.

Why not use the '-w' flag for grep to match on a whole word?

Type man killall for a revelation.

Old game from 2005 mac os. ditto

I found this command immediately after submitting this script. doh.

live and learn - we all do

**this is not a flame it's meant to be constructive critisim**
at the least you should not be matching things like ssh-agent if you choose ssh with this script. that is just wrong. sorry! because if you do that you can trigger all sorts of problems killing processes that you did not intend to kill..
this script is a duplication of functionality and while it is intersting and duplication of functionality is kinda what open source is all about this script is just dangerous!!!!
granted that the danger is minmal, esp if the script is not run as the superuser.. there is little you can do, but throwing around kill's arbitrarily will screw things up!
for example i have both inetd and xinetd running here for some reason??? anyone know why??? and if i ran your script with 'inetd' it would kill inetd && xinetd that's just wrong.. especially when there are better tools on the system that will do the job properly 'killall' ????
i'm not trying to be rude at all but.. at least do exact process name matching.

a modification for pidof to kill..
the default is to send a sighup but you can kill too
ie ./kill name sig
place this script somewhere and chmod it 755
it's the perl version so the matching is better!
the base for this code came from someone who submitted a perl version as a comment to my bash&tr&awk pidof script, i forget his name but just want to make people know it's not entirely my own. but heavily modified.

#!/usr/bin/perl
$search=$ARGV[0];
if ($ARGV[1]) {$sig=$ARGV[1]; } else { $sig=1; }
@procs = `ps -cxa`;
for $proc (@procs ) {
if( $proc =~ /s+(d+)s+S+s+S+s+S+s+(S+)/ ) {
$pid = $1;
$name = $2;
if( $name =~ /^$search$/ ) {
kill $sig,$pid;
print '$pid ';
}
}
}
print 'n';

I read both this hint and the A bash script to kill a process hint, and even read parts of the post where some users said to use the 'killall' command. None worked for my case where the app name contained spaces in the name, like Internet Explorer.app. To make sure I am not nuts, try the above hints yourself because I would prefer a smaller bit of code then what I wrote below. Also it is in PHP, I was not cool enough to write it in a unix shell script.




broken image