Force kill process by name on Linux Centos Redhat RHEL Fedora Ubuntu

Force kill process by name on Linux Centos Redhat RHEL Fedora Ubuntu

You want to kill one process by name not by process ID.

1. Example you are checking all process in running on your Linux

[root@localhost ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jan26 ? 00:00:01 /sbin/init
root 2 0 0 Jan26 ? 00:00:00 [kthreadd]
root 3 2 0 Jan26 ? 00:00:00 [migration/0]
root 4 2 0 Jan26 ? 00:00:04 [ksoftirqd/0]
root 5 2 0 Jan26 ? 00:00:00 [migration/0]
root 6 2 0 Jan26 ? 00:00:01 [watchdog/0]
root 7 2 0 Jan26 ? 00:01:17 [events/0]
root 8 2 0 Jan26 ? 00:00:00 [cgroup]
root 9 2 0 Jan26 ? 00:00:00 [khelper]
root 10 2 0 Jan26 ? 00:00:00 [netns]
root 11 2 0 Jan26 ? 00:00:00 [async/mgr]
root 12 2 0 Jan26 ? 00:00:00 [pm]
root 13 2 0 Jan26 ? 00:00:01 [sync_supers]
root 14 2 0 Jan26 ? 00:00:01 [bdi-default]
root 15 2 0 Jan26 ? 00:00:00 [kintegrityd/0]
root 16 2 0 Jan26 ? 00:00:12 [kblockd/0]
root 17 2 0 Jan26 ? 00:00:00 [kacpid]
root 18 2 0 Jan26 ? 00:00:00 [kacpi_notify]
root 19 2 0 Jan26 ? 00:00:00 [kacpi_hotplug]
root 20 2 0 Jan26 ? 00:00:22 [ata/0]
root 21 2 0 Jan26 ? 00:00:00 [ata_aux]
root 22 2 0 Jan26 ? 00:00:00 [ksuspend_usbd]
root 23 2 0 Jan26 ? 00:00:00 [khubd]
root 24 2 0 Jan26 ? 00:00:00 [kseriod]
root 25 2 0 Jan26 ? 00:00:00 [md/0]
root 26 2 0 Jan26 ? 00:00:00 [md_misc/0]
root 27 2 0 Jan26 ? 00:00:00 [khungtaskd]
root 28 2 0 Jan26 ? 00:00:03 [kswapd0]
root 29 2 0 Jan26 ? 00:00:00 [ksmd]
root 30 2 0 Jan26 ? 00:00:13 [khugepaged]
root 31 2 0 Jan26 ? 00:00:00 [aio/0]
root 32 2 0 Jan26 ? 00:00:00 [crypto/0]
root 37 2 0 Jan26 ? 00:00:00 [kthrotld/0]
root 38 2 0 Jan26 ? 00:00:00 [pciehpd]
root 40 2 0 Jan26 ? 00:00:00 [kpsmoused]
root 41 2 0 Jan26 ? 00:00:00 [usbhid_resumer]
root 71 2 0 Jan26 ? 00:00:00 [kstriped]
root 252 2 0 Jan26 ? 00:00:00 [scsi_eh_0]
root 257 2 0 Jan26 ? 00:00:29 [scsi_eh_1]
root 269 2 0 Jan26 ? 00:00:06 [mpt_poll_0]
root 270 2 0 Jan26 ? 00:00:00 [mpt/0]
root 271 2 0 Jan26 ? 00:00:00 [scsi_eh_2]
root 370 2 0 Jan26 ? 00:00:08 [flush-8:0]
root 371 2 0 Jan26 ? 00:00:11 [jbd2/sda2-8]
root 372 2 0 Jan26 ? 00:00:00 [ext4-dio-unwrit]
root 457 1 0 Jan26 ? 00:00:00 /sbin/udevd -d
root 650 2 0 Jan26 ? 00:00:06 [vmmemctl]
root 1096 2 0 Jan26 ? 00:00:00 [jbd2/sda1-8]
root 1097 2 0 Jan26 ? 00:00:00 [ext4-dio-unwrit]
root 1190 2 0 Jan26 ? 00:00:00 [kauditd]
root 1485 1 0 Jan26 ? 00:00:00 /usr/sbin/vmware-vmblock-fuse -o subtype=vmware-vmblock,default_permissions,allow_other /var/run/vmblock-fuse
root 1507 1 0 Jan26 ? 00:06:47 /usr/sbin/vmtoolsd
root 1772 1 0 Jan26 ? 00:00:00 auditd
root 1790 1 0 Jan26 ? 00:00:00 /sbin/portreserve
root 1797 1 0 Jan26 ? 00:00:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
dbus 1850 1 0 Jan26 ? 00:00:02 dbus-daemon –system
root 1861 1 0 Jan26 ? 00:00:01 NetworkManager –pid-file=/var/run/NetworkManager/NetworkManager.pid
root 1866 1 0 Jan26 ? 00:00:00 /usr/sbin/modem-manager
avahi 1873 1 0 Jan26 ? 00:00:00 avahi-daemon: running [linux.local]
avahi 1874 1873 0 Jan26 ? 00:00:00 avahi-daemon: chroot helper
root 1889 1 0 Jan26 ? 00:00:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid
root 1890 1 0 Jan26 ? 00:00:00 cupsd -C /etc/cups/cupsd.conf
root 1909 2 0 Jan26 ? 00:00:00 [kslowd000]
root 1910 2 0 Jan26 ? 00:00:00 [kslowd001]
root 1911 2 0 Jan26 ? 00:00:00 [cifsiod]
root 1931 1 0 Jan26 ? 00:00:00 /usr/sbin/acpid
68 1940 1 0 Jan26 ? 00:00:00 hald
root 1941 1940 0 Jan26 ? 00:00:00 hald-runner
root 1981 1941 0 Jan26 ? 00:00:00 hald-addon-input: Listening on /dev/input/event2 /dev/input/event0
68 1986 1941 0 Jan26 ? 00:00:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket
root 2008 1 0 Jan26 ? 00:00:00 /usr/sbin/sshd
root 2046 1 0 Jan26 ? 00:00:02 tpvmlpd2
root 2160 1 0 Jan26 ? 00:00:00 /usr/libexec/postfix/master
postfix 2169 2160 0 Jan26 ? 00:00:00 qmgr -l -t fifo -u
root 2184 1 0 Jan26 ? 00:00:00 /usr/sbin/abrtd
root 2192 1 0 Jan26 ? 00:00:00 abrt-dump-oops -d /var/spool/abrt -rwx /var/log/messages
root 2214 1 0 Jan26 ? 00:00:02 crond
root 2225 1 0 Jan26 ? 00:00:00 /usr/sbin/atd
root 2239 1 0 Jan26 ? 00:00:00 /usr/sbin/gdm-binary -nodaemon
root 2244 1 0 Jan26 tty2 00:00:00 /sbin/mingetty /dev/tty2
root 2246 1 0 Jan26 tty3 00:00:00 /sbin/mingetty /dev/tty3
root 2248 1 0 Jan26 tty4 00:00:00 /sbin/mingetty /dev/tty4
root 2251 457 0 Jan26 ? 00:00:00 /sbin/udevd -d
root 2253 1 0 Jan26 tty5 00:00:00 /sbin/mingetty /dev/tty5
root 2254 457 0 Jan26 ? 00:00:00 /sbin/udevd -d
root 2256 1 0 Jan26 tty6 00:00:00 /sbin/mingetty /dev/tty6
root 2267 2239 0 Jan26 ? 00:00:00 /usr/libexec/gdm-simple-slave –display-id /org/gnome/DisplayManager/Display1 –force-active-vt
root 2269 2267 0 Jan26 tty1 00:00:11 /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-r5u5JE/database -nolisten tcp vt1
root 2284 1 0 Jan26 ? 00:00:00 /usr/sbin/console-kit-daemon –no-daemon
gdm 2354 1 0 Jan26 ? 00:00:00 /usr/bin/dbus-launch –exit-with-session
root 2360 1 0 Jan26 ? 00:00:00 /usr/libexec/devkit-power-daemon
root 2401 1 0 Jan26 ? 00:00:00 /usr/libexec/polkit-1/polkitd
rtkit 2413 1 0 Jan26 ? 00:00:01 /usr/libexec/rtkit-daemon
root 2418 2267 0 Jan26 ? 00:00:00 pam: gdm-password
root 2545 1 0 Jan26 ? 00:00:00 /usr/bin/gnome-keyring-daemon –daemonize –login
root 2554 2418 0 Jan26 ? 00:00:00 gnome-session
root 2562 1 0 Jan26 ? 00:00:00 dbus-launch –sh-syntax –exit-with-session
root 2563 1 0 Jan26 ? 00:00:00 /bin/dbus-daemon –fork –print-pid 5 –print-address 7 –session
root 2577 1 0 Jan26 ? 00:00:03 /usr/libexec/gconfd-2
root 2586 1 0 Jan26 ? 00:00:11 /usr/libexec/gnome-settings-daemon
root 2591 1 0 Jan26 ? 00:00:00 /usr/libexec/gvfsd
root 2595 1 0 Jan26 ? 00:00:00 /usr/libexec//gvfs-fuse-daemon /root/.gvfs
root 2598 1 0 Jan26 ? 00:00:00 seahorse-daemon
root 2601 2554 0 Jan26 ? 00:00:00 metacity
root 2603 2554 0 Jan26 ? 00:00:09 gnome-panel
root 2615 2554 0 Jan26 ? 00:00:09 nautilus
root 2617 1 0 Jan26 ? 00:00:00 /usr/libexec/bonobo-activation-server –ac-activate –ior-output-fd=18
root 2627 1 0 Jan26 ? 00:00:00 /usr/libexec/wnck-applet –oaf-activate-iid=OAFIID:GNOME_Wncklet_Factory –oaf-ior-fd=18
root 2628 1 0 Jan26 ? 00:00:00 /usr/libexec/trashapplet –oaf-activate-iid=OAFIID:GNOME_Panel_TrashApplet_Factory –oaf-ior-fd=24
root 2630 1 0 Jan26 ? 00:00:00 /usr/libexec/gvfs-gdu-volume-monitor
root 2632 1 0 Jan26 ? 00:00:00 /usr/libexec/udisks-daemon
root 2634 1 0 Jan26 ? 00:00:00 /usr/libexec/gvfsd-trash –spawner :1.7 /org/gtk/gvfs/exec_spaw/0
root 2635 2632 0 Jan26 ? 00:01:03 udisks-daemon: polling /dev/sr0
root 2637 1 0 Jan26 ? 00:00:05 /usr/libexec/gvfs-afc-volume-monitor
root 2640 1 0 Jan26 ? 00:00:00 /usr/libexec/gvfs-gphoto2-volume-monitor
root 2645 1 0 Jan26 ? 00:00:00 /usr/bin/gnote –panel-applet –oaf-activate-iid=OAFIID:GnoteApplet_Factory –oaf-ior-fd=19
root 2646 1 0 Jan26 ? 00:00:00 /usr/libexec/notification-area-applet –oaf-activate-iid=OAFIID:GNOME_NotificationAreaApplet_Factory –oaf-ior-fd=40
root 2647 1 0 Jan26 ? 00:00:00 /usr/libexec/gdm-user-switch-applet –oaf-activate-iid=OAFIID:GNOME_FastUserSwitchApplet_Factory –oaf-ior-fd=34
root 2648 1 0 Jan26 ? 00:00:02 /usr/libexec/clock-applet –oaf-activate-iid=OAFIID:GNOME_ClockApplet_Factory –oaf-ior-fd=28
root 2659 1 0 Jan26 ? 00:05:23 /usr/lib/vmware-tools/sbin64/vmtoolsd -n vmusr –blockFd 3
root 2668 2554 0 Jan26 ? 00:00:00 gpk-update-icon
root 2674 2554 0 Jan26 ? 00:00:00 nm-applet –sm-disable
root 2678 2554 0 Jan26 ? 00:00:00 bluetooth-applet
root 2681 2554 0 Jan26 ? 00:00:00 python /usr/share/system-config-printer/applet.py
root 2686 2554 0 Jan26 ? 00:00:00 gnome-volume-control-applet
root 2690 1 0 Jan26 ? 00:00:01 /usr/bin/pulseaudio –start
root 2691 2554 0 Jan26 ? 00:00:00 /usr/libexec/polkit-gnome-authentication-agent-1
root 2692 2554 0 Jan26 ? 00:00:00 gnome-power-manager
root 2694 2554 0 Jan26 ? 00:00:00 /usr/libexec/gdu-notification-daemon
root 2695 1 0 Jan26 ? 00:00:08 gnome-screensaver
root 2701 2690 0 Jan26 ? 00:00:00 /usr/libexec/pulse/gconf-helper
root 2707 1 0 Jan26 ? 00:00:00 /usr/sbin/restorecond -u
root 2731 1 0 Jan26 ? 00:00:00 /usr/libexec/gvfsd-burn –spawner :1.7 /org/gtk/gvfs/exec_spaw/1
root 2734 1 0 Jan26 ? 00:00:00 /usr/libexec/gvfsd-metadata
root 2742 1 0 Jan26 ? 00:00:00 /usr/bin/gnome-terminal -x /bin/sh -c cd ‘/root/Desktop’ && exec $SHELL
root 2743 2742 0 Jan26 ? 00:00:00 gnome-pty-helper
root 2744 2742 0 Jan26 pts/0 00:00:00 /bin/bash
root 4441 1 0 Jan26 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe –datadir=/var/lib/mysql –socket=/var/lib/mysql/mysql.sock –pid-file=/var/run/mysqld/mysqld.pid –basedir=/usr –user=
mysql 4530 4441 0 Jan26 ? 00:00:23 /usr/libexec/mysqld –basedir=/usr –datadir=/var/lib/mysql –user=mysql –log-error=/var/log/mysqld.log –pid-file=/var/run/mysqld/mysqld.pid –sock
root 4560 1 0 Jan26 ? 00:00:32 /usr/sbin/snmpd -LS0-6d -Lf /dev/null -p /var/run/snmpd.pid
root 5864 1861 0 Jan26 ? 00:00:00 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-eth0.pid -lf /var/lib/dhclient/dhclient-5cf25a5d-78db-42ab-b89b-13d
root 5912 2 0 Jan26 ? 00:00:01 [cifsd]
root 23964 1 0 Jan27 ? 00:07:23 /usr/lib64/firefox/firefox
root 23982 23964 0 Jan27 ? 00:00:00 [firefox] <defunct>
postfix 46419 2160 0 02:10 ? 00:00:00 pickup -l -t fifo -u
root 46939 2008 0 02:44 ? 00:00:00 sshd: root@pts/1
root 46944 46939 0 02:44 pts/1 00:00:00 -bash
root 47131 1 0 02:54 ? 00:00:00 /usr/sbin/packagekitd
root 47132 47131 5 02:54 ? 00:00:02 /usr/bin/python /usr/share/PackageKit/helpers/yum/yumBackend.py refresh-cache yes
root 47160 1 0 02:55 ? 00:00:00 /usr/sbin/httpd
apache 47163 47160 0 02:55 ? 00:00:00 /usr/sbin/httpd
apache 47164 47160 0 02:55 ? 00:00:00 /usr/sbin/httpd
apache 47165 47160 0 02:55 ? 00:00:00 /usr/sbin/httpd
apache 47166 47160 0 02:55 ? 00:00:00 /usr/sbin/httpd
apache 47168 47160 0 02:55 ? 00:00:00 /usr/sbin/httpd
apache 47169 47160 0 02:55 ? 00:00:00 /usr/sbin/httpd
apache 47170 47160 0 02:55 ? 00:00:00 /usr/sbin/httpd
apache 47171 47160 0 02:55 ? 00:00:00 /usr/sbin/httpd
root 47172 46944 2 02:55 pts/1 00:00:00 ps -ef
[root@localhost ~]#

2. You want to kill process name “httpd” in the name

[root@localhost ~]# kill -9 `ps -ef | grep ‘httpd’ | grep -v grep | awk ‘{print $2}’`

Syntax:

kill -9 `ps -ef | grep ‘name’ | grep -v grep | awk ‘{print $2}’`

3. Check the process on ps

[root@localhost ~]# ps -ef | grep httpd
root 47217 46944 0 02:58 pts/1 00:00:00 grep httpd
[root@localhost ~]#

So process is killed by name.

That’s all. Thanks for using IThelpblog.com.

 

 

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>