How to kill all processes except shell window?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to kill all processes except shell window?
# 1  
Old 08-03-2010
How to kill all processes except shell window?

Hi i was referring to an article given in following website.
Basic shell scripting questions | TechInterviews
I was surprise to know that i can kill all running processes by using kill o.
However when i tried running the command nothing happened.

How would i establish this task?
my machine details:
Code:
# lsb_release -a
LSB Version:    :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: EnterpriseEnterpriseServer
Description:    Enterprise Linux Enterprise Linux Server release 5.2 (Carthage)
Release:        5.2
Codename:       Carthage

# 2  
Old 08-03-2010
its kill 0(zero) ...and i think you tried with o (character) its zero actually.
# 3  
Old 08-03-2010
Quote:
Originally Posted by sachinkl
its kill 0(zero) ...and i think you tried with o (character) its zero actually.
i tried kill 0 but still there are lot of processes running please see the output of below commands.

Code:
# kill 0
# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 16:12 ?        00:00:07 init [5]
root         2     1  0 16:12 ?        00:00:00 [migration/0]
root         3     1  0 16:12 ?        00:00:00 [ksoftirqd/0]
root         4     1  0 16:12 ?        00:00:00 [watchdog/0]
root         5     1  0 16:12 ?        00:00:00 [events/0]
root         6     1  0 16:12 ?        00:00:00 [khelper]
root         7     1  0 16:12 ?        00:00:00 [kthread]
root        10     7  0 16:12 ?        00:00:00 [kblockd/0]
root        11     7  0 16:12 ?        00:00:00 [kacpid]
root        47     7  0 16:12 ?        00:00:00 [cqueue/0]
root        50     7  0 16:12 ?        00:00:00 [khubd]
root        52     7  0 16:12 ?        00:00:00 [kseriod]
root       115     7  0 16:12 ?        00:00:00 [pdflush]
root       116     7  0 16:12 ?        00:00:00 [pdflush]
root       117     7  0 16:12 ?        00:00:00 [kswapd0]
root       118     7  0 16:12 ?        00:00:00 [aio/0]
root       273     7  0 16:12 ?        00:00:00 [kpsmoused]
root       297     7  0 16:12 ?        00:00:00 [ata/0]
root       298     7  0 16:12 ?        00:00:00 [ata_aux]
root       309     7  0 16:12 ?        00:00:00 [ksnapd]
root       312     7  0 16:12 ?        00:00:00 [kjournald]
root       345     7  0 16:12 ?        00:00:00 [kauditd]
root       379     1  0 16:12 ?        00:00:00 /sbin/udevd -d
root      3711     7  0 16:13 ?        00:00:00 [kmpathd/0]
root      3735     7  0 16:13 ?        00:00:00 [kjournald]
root      4173     1  0 16:13 ?        00:00:00 auditd
root      4175  4173  0 16:13 ?        00:00:00 /sbin/audispd
root      4192     1  0 16:13 ?        00:00:00 /usr/sbin/restorecond
root      4203     1  0 16:13 ?        00:00:00 syslogd -m 0
root      4206     1  0 16:13 ?        00:00:00 klogd -x
root      4232     1  0 16:13 ?        00:00:00 mcstransd
rpc       4245     1  0 16:13 ?        00:00:00 portmap
root      4258     1  0 16:13 ?        00:00:00 /usr/bin/python -E /usr/sbin/set
root      4279     1  0 16:13 ?        00:00:00 rpc.statd
root      4315     1  0 16:13 ?        00:00:00 rpc.idmapd
dbus      4334     1  0 16:13 ?        00:00:00 dbus-daemon --system
root      4346     1  0 16:13 ?        00:00:00 /usr/sbin/hcid
root      4350     1  0 16:13 ?        00:00:00 /usr/sbin/sdpd
root      4372     1  0 16:13 ?        00:00:00 [krfcommd]
root      4413     1  0 16:13 ?        00:00:00 pcscd
root      4433     1  0 16:13 ?        00:00:00 /usr/bin/hidd --server
root      4448     1  0 16:13 ?        00:00:00 automount
root      4467     1  0 16:13 ?        00:00:00 /usr/sbin/acpid
root      4478     1  0 16:13 ?        00:00:00 ./hpiod
root      4483     1  0 16:13 ?        00:00:00 python ./hpssd.py
root      4498     1  0 16:13 ?        00:00:00 /usr/sbin/sshd
root      4509     1  0 16:13 ?        00:00:00 cupsd
root      4521     1  0 16:13 ?        00:00:00 xinetd -stayalive -pidfile /var/
oracle    4538     1  0 16:13 ?        00:00:00 /usr/lib/oracle/xe/app/oracle/pr
oracle    4543     1  0 16:13 ?        00:00:00 xe_pmon_XE
oracle    4545     1  0 16:13 ?        00:00:00 xe_psp0_XE
oracle    4547     1  0 16:13 ?        00:00:00 xe_mman_XE
oracle    4549     1  0 16:13 ?        00:00:00 xe_dbw0_XE
oracle    4551     1  0 16:13 ?        00:00:00 xe_lgwr_XE
oracle    4553     1  0 16:13 ?        00:00:00 xe_ckpt_XE
oracle    4555     1  0 16:13 ?        00:00:00 xe_smon_XE
oracle    4557     1  0 16:13 ?        00:00:00 xe_reco_XE
oracle    4559     1  0 16:13 ?        00:00:00 xe_cjq0_XE
oracle    4561     1  0 16:13 ?        00:00:01 xe_mmon_XE
oracle    4563     1  0 16:13 ?        00:00:00 xe_mmnl_XE
oracle    4565     1  0 16:13 ?        00:00:00 xe_d000_XE
oracle    4567     1  0 16:13 ?        00:00:00 xe_s000_XE
oracle    4569     1  0 16:13 ?        00:00:00 xe_s001_XE
oracle    4571     1  0 16:13 ?        00:00:00 xe_s002_XE
oracle    4573     1  0 16:13 ?        00:00:00 xe_s003_XE
oracle    4577     1  0 16:14 ?        00:00:00 xe_qmnc_XE
root      4596     1  0 16:14 ?        00:00:00 sendmail: accepting connections
smmsp     4605     1  0 16:14 ?        00:00:00 sendmail: Queue runner@01:00:00
root      4617     1  0 16:14 ?        00:00:00 gpm -m /dev/input/mice -t exps2
root      4638     1  0 16:14 ?        00:00:00 crond
xfs       4669     1  0 16:14 ?        00:00:00 xfs -droppriv -daemon
oracle    4681     1  0 16:14 ?        00:00:00 xe_q000_XE
oracle    4683     1  0 16:14 ?        00:00:00 xe_q001_XE
root      4684     1  0 16:14 ?        00:00:00 smbd -D
root      4687     1  0 16:14 ?        00:00:00 nmbd -D
root      4699  4684  0 16:14 ?        00:00:00 smbd -D
root      4709     1  0 16:14 ?        00:00:04 /usr/java/jdk1.6.0_20/bin/java -
root      4719     1  0 16:14 ?        00:00:00 anacron -s
root      4729     1  0 16:14 ?        00:00:00 /usr/sbin/atd
avahi     4777     1  0 16:14 ?        00:00:00 avahi-daemon: running [TomcatSer
avahi     4778  4777  0 16:14 ?        00:00:00 avahi-daemon: chroot helper
68        4793     1  0 16:14 ?        00:00:01 hald
root      4794  4793  0 16:14 ?        00:00:00 hald-runner
68        4805  4794  0 16:14 ?        00:00:00 hald-addon-acpi: listening on ac
68        4809  4794  0 16:14 ?        00:00:00 hald-addon-keyboard: listening o
root      4820  4794  0 16:14 ?        00:00:00 hald-addon-storage: polling /dev
root      4897     1  0 16:14 ?        00:00:00 /usr/sbin/smartd -q never
root      4902     1  0 16:14 tty1     00:00:00 /sbin/mingetty tty1
root      4903     1  0 16:14 tty2     00:00:00 /sbin/mingetty tty2
root      4904     1  0 16:14 tty3     00:00:00 /sbin/mingetty tty3
root      4905     1  0 16:14 tty4     00:00:00 /sbin/mingetty tty4
root      4912     1  0 16:14 tty5     00:00:00 /sbin/mingetty tty5
root      4913     1  0 16:14 tty6     00:00:00 /sbin/mingetty tty6
root      4914     1  0 16:14 ?        00:00:00 /usr/sbin/gdm-binary -nodaemon
root      5002  4914  0 16:14 ?        00:00:00 /usr/sbin/gdm-binary -nodaemon
root      5004     1  0 16:14 ?        00:00:00 /usr/libexec/gdm-rh-security-tok
root      5007  5002  0 16:14 tty7     00:00:00 /usr/bin/Xorg :0 -br -audit 0 -a
gdm       5028  5002  0 16:14 ?        00:00:00 /usr/libexec/gdmgreeter
root      5029     1  0 16:14 ?        00:00:00 /usr/bin/python -tt /usr/sbin/yu
root      5031     1  0 16:14 ?        00:00:00 /usr/libexec/gam_server
root      5068  4498  0 16:18 ?        00:00:00 sshd: root@pts/1
root      5071  5068  0 16:18 pts/1    00:00:00 -bash
root      5160  5071  0 16:37 pts/1    00:00:00 ps -ef

# 4  
Old 08-03-2010
Read up on kill.
  1. A user can not kill processes owned by other users, unless the user is root
  2. From the info page of kill (GNU version):
    Quote:
    If PID is positive, the signal is sent to the process with the process ID PID. If PID is zero, the signal is sent to all processes in the process group of the current process.
    This, more or less, means that a "kill 0" only kills the processes spawned by the current shell, unless they started their own process group (eg. daemonized).
# 5  
Old 08-03-2010
Quote:
Originally Posted by pludi
Read up on kill.
  1. A user can not kill processes owned by other users, unless the user is root
  2. From the info page of kill (GNU version):
    This, more or less, means that a "kill 0" only kills the processes spawned by the current shell, unless they started their own process group (eg. daemonized).
I have tried these option being root user itself.
I guess -0 option is used to check if the process is running or not.
and there is no such command to kill all processes except shell window .
Correct me if i m wrong.


Code:
	# kill -0 5071
[root@TomcatServer ~]# echo $?
0
[root@TomcatServer ~]# kill -0 5169
-bash: kill: (5169) - No such process
[root@TomcatServer ~]# echo $?
1



---------- Post updated at 01:05 AM ---------- Previous update was at 01:01 AM ----------

my question is still not answered how would i kill all processes except current shell window?(considering i have login with a root user).
# 6  
Old 08-03-2010
There's a difference between "kill -0 <pid>" and "kill 0". The former sends no signal to a process, but just checks if that process exists. The later sends SIGTERM to all processes in the current process group. In theory, every process could be in it's own group, so nothing would be killed.

Also, even root can't kill all processes. Some of those listed above (those in square brackets) are actually kernel threads. And I don't think init can be killed. You can send a signal to a different process group by running
Code:
kill -<pgid>

where pgid is the process group ID. This you can get by running
Code:
ps axj

This User Gave Thanks to pludi For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

kill multiple processes by name

Want to kill multiple processes by name. for the example below, I want to kill all 'proxy-stagerd_copy' processes. I tried this but didn't work: >> ps -ef|grep proxy_copy root 991 986 0 14:45:34 ? 0:04 proxy-stagerd root 1003 991 0 14:45:49 ? 0:01... (2 Replies)
Discussion started by: catalinawinemxr
2 Replies

2. Shell Programming and Scripting

need to kill a number of processes with name "XYZ" at a time using shell script

Hi, when i grep for the process "XYZ" , there will be some good number of processes with that name, i want to kill all the these processes at a time using shell script? Any help needed for this action. Thanks Regards, Anil (6 Replies)
Discussion started by: anilmanepu
6 Replies

3. Shell Programming and Scripting

kill all user processes

Hi there, i've been searching all over and i thought i had understood the way i should go to kill all the processes related to a user. But i'm getting more confused then i was. By lunch time i have to make a database backup, and for that all the users shoul logout. The problem is that many users... (4 Replies)
Discussion started by: vascobrito
4 Replies

4. Shell Programming and Scripting

Kill processes

for i in 'ps -f | grep textedit' do kill $i done I wrote this but it wont work. I am trying to find processes and kill them. Any help would be welcome. (1 Reply)
Discussion started by: hawaiifiver
1 Replies

5. UNIX for Dummies Questions & Answers

Need help to kill parent and all of its sub processes

Hi, I am writing korn shell script. My requirement is, i have to kill the parent process and all of its child processes. Can some one please help me on this? Thanks in advance for your help.. (1 Reply)
Discussion started by: Sheethal
1 Replies

6. Solaris

kill the processes seen under ptree

Hi, How to kill the processes running under ptree ? I am noticing lot of processes running under ptree with ssh ? I tried to kill with -9 option which is not working ? Thanks, Radhika. (2 Replies)
Discussion started by: radhirk
2 Replies

7. Solaris

kill processes

how to kill the processes of aperticular user? because i have nearly 25000 process are there for perticular user. i need to kill. Please provide the information? Regards, Rajesh (3 Replies)
Discussion started by: pmrajesh21
3 Replies

8. Solaris

how do I kill defunct processes?

mqm 17700 16815 0 0:00 <defunct> kill -9 does not work, even as root (10 Replies)
Discussion started by: csaunders
10 Replies

9. Shell Programming and Scripting

Unix Kill processes

Hi guys, I am new to Unix shell scripting. Can anyone of you tell me how to kill all the processes at a time for a particular user?(No listing the process ID of each process in the kill -9 command). Thanks in Advance, -Hary (5 Replies)
Discussion started by: tadi18
5 Replies

10. Shell Programming and Scripting

kill all processes

i have a very short file that has in it a line for a find command. now, when i run this script and I kill the script later, using the ps -ef | grep scriptname. i noticed kill -9 kills the script itself but does not kill the internal find command that it gave birth to. say theres a file... (0 Replies)
Discussion started by: Terrible
0 Replies
Login or Register to Ask a Question