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
A user can not kill processes owned by other users, unless the user is root
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