export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin export IFS=$' \t\n' /usr/bin/sudo /bin/mkdir -p /usr/local/bin /usr/bin/sudo /usr/sbin/chown root:wheel /usr/local /usr/local/bin /usr/bin/sudo /bin/chmod 0755 /usr/local /usr/local/bin ls -ld /usr/local /usr/local/bin man killall | less -p 'Show only' help kill # cf. also http://sial.org/howto/shell/kill-9/ and # http://sial.org/blog/2006/10/kill_only_if_not_already_dead.html man signal | less -p 'Default Action' man sigaction | less -p 'Default Action' man kill | less -p 'commonly used signals' kill -l kill -l 1 2 3 15 help type type -t kill killall type -a kill killall # the -s option just triggers a fake kill killall -s Finder killall -s -HUP Finder killall -s -9 Finder killall -s -3 Finder # cf. http://bashcurescancer.com/using-kill-to-see-if-a-process-is-alive.html open -a 'Activity Monitor' killall -s Terminal kill -0 3832 &>/dev/null; echo $? # no process with ID 3832 running if exit status is 1 kill -0 $(killall -s Terminal | awk '{print $NF}') &>/dev/null; echo $? # Terminal is alive kill -0 $PPID &>/dev/null; echo $? # Bash is alive # kpid - get PID using killall -s /bin/cat > ~/Desktop/kpid <<-'EOF' #!/bin/sh declare kpid rc kpid=$(/usr/bin/killall -s -u $(/usr/bin/id -u) "${@}" 2>/dev/null) rc=$? if [[ $rc -eq 0 ]]; then printf "%s" "$kpid" | awk '{print $NF}' else exit 1 fi exit 0 EOF /usr/bin/sudo /bin/mv -i ~/Desktop/kpid /usr/local/bin /usr/bin/sudo /usr/sbin/chown root:wheel /usr/local/bin/kpid /usr/bin/sudo /bin/chmod 0755 /usr/local/bin/kpid /usr/bin/sudo /usr/bin/nano /usr/local/bin/kpid open -a 'Activity Monitor' kpid Finder kpid Safari kpid Dock kpid TextEdit kpid 'QuickTime Player' kpid launchd /usr/bin/sudo pid launchd kpid cupsd; echo $? /usr/bin/sudo kpid cupsd kpid bash /usr/bin/sudo kpid bash; echo $? # kill Bash #echo $PPID #kill -HUP $PPID #kill -KILL $PPID #--------------------------------------------------------------- man ps ps -L | tr ' ' '\n' # pspid - get PID using ps /bin/cat > ~/Desktop/pspid <<-'EOF' #!/bin/sh declare pspid if [[ "$1" = "-l" ]]; then #if [[ $# -eq 1 ]]; then /bin/ps -r -axco pid,command; exit 0; fi #if [[ $# -eq 1 ]]; then /bin/ps -axco pid,command | /usr/bin/sed '1,1d' | /usr/bin/sort -rn ; exit 0; fi if [[ $# -eq 1 ]]; then /bin/ps -axco pid,command | /usr/bin/sed '1,1d' | /usr/bin/sort -n ; exit 0; fi #pspid="$(/bin/ps -axco pid,command | /usr/bin/awk "/${2}/ { print \$1,\$2 }")" #printf "%-15s %-15s\n" $(printf "%s" "$pspid" | /usr/bin/sort -n) #pspid="$(/bin/ps -axco pid,command,uid | /usr/bin/awk "/${2}/ { print \$1,\$2,\$3 }")" #printf "%-20s %-20s %-20s\n" $(printf "%s" "$pspid" | /usr/bin/sort -n) #pspid="$(/bin/ps -axco pid,command,uid,user | /usr/bin/awk "/${2}/ {print \$1,\$2,\$3,\$4}")" #printf "%-20s %-20s %-20s %-20s\n" $(printf "%s" "$pspid" | /usr/bin/sort -n) pspid="$(/bin/ps -axco pid,command,uid,user,tty | /usr/bin/awk "/${2}/ {print \$1,\$2,\$3,\$4,\$5}")" printf "%-20s %-20s %-20s %-20s %-20s\n" $(printf "%s" "$pspid" | /usr/bin/sort -n) exit 0 fi pspid="$(/bin/ps -axco pid,command | /usr/bin/awk "/${@}/ {print \$1}")" if [[ -n "$pspid" ]]; then printf "%s\n" "$pspid" else exit 1 fi exit 0 EOF /usr/bin/sudo /bin/mv -i ~/Desktop/pspid /usr/local/bin /usr/bin/sudo /usr/sbin/chown root:wheel /usr/local/bin/pspid /usr/bin/sudo /bin/chmod 0755 /usr/local/bin/pspid /usr/bin/sudo /usr/bin/nano /usr/local/bin/pspid open -a 'Activity Monitor' pspid Finder pspid Safari pspid TextEdit pspid 'QuickTime Player' pspid login pspid dynamic_pager pspid launchd pspid bash echo $PPID pspid -l pspid -l login pspid -l launchd pspid -l bash pspid -l '.*[sS]erver.*' pspid -l '.*d$' pspid -l '.*' | grep nobody pspid -l '.*' | grep root
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Get process ID (PID) via ps or killall (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» mycmds in awk shell osx mac bash bashrc unix debug profile escape alias
» List manual pages and system... in awk shell osx mac bash cmd unix commands list man manpages
» Changing the Finder "Open Wi... in awk shell osx mac bash unix finder file application open menu contextual lsregister duti with wsupdate
» Counting lines in awk grep shell osx mac bash line unix count file sed directory lines wc
» Process positional parameter... in shell osx mac bash command line unix process parameter extract argument cmdparser positional
» Simple internet traffic summ... in awk shell osx mac bash unix web internet traffic summary tcpdump
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails