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:

# 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

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.

# 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

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.
    [/quote]

    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.

	# 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).

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

kill -<pgid>

where pgid is the process group ID. This you can get by running

ps axj