LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-03-2010, 12:23 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
How to kill all processes except shell window?


Hi i was referring to an article given in following website.
http://www.techinterviews.com/basic-...ting-questions
I was surprise to know that i can kill all running processes by using kill 0.
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

Last edited by pinga123; 06-21-2011 at 05:06 AM. Reason: kill o is modified to kill 0
 
Old 08-03-2010, 12:34 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Yes, that a commonly cited "fact" on sites like www.techinterviews.com. And it's utter nonsense.

Here's the truth about "kill -0" (note: "dash zero", not "little oh"):
Quote:
http://www.linuxjournal.com/content/...ocesses-kill-0

If you have a process ID but aren't sure whether it's valid, you can use the most unlikely of candidates to test it: the kill command. If you don't see any reference to this on the kill(1) man page, check the info pages. The man/info page states that signal 0 is special and that the exit code from kill tells whether a signal could be sent to the specified process (or processes).

So kill -0 will not terminate the process, and the return status can be used to determine whether a process is running
Now THAT's an answer that might impress an interviewer
 
Old 08-03-2010, 12:39 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by paulsm4 View Post
Hi -

Yes, that a commonly cited "fact" on sites like www.techinterviews.com. And it's utter nonsense.

Here's the truth about "kill -0" (note: "dash zero", not "little oh"):


Now THAT's an answer that might impress an interviewer
So it 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

Last edited by pinga123; 08-03-2010 at 12:43 AM.
 
Old 08-03-2010, 02:04 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
I don't know what do you mean when you say "except shell window".

First, the shell is one thing and the "window" (whatever window it is) is a completely different thing/process. Even more, if you have such a thing as a window then you are definitely not running just a couple of processes, because that means you are in X, which is probably run via a wrapper (xinit or whatever else) which also runs a window manager (or more likely, a desktop) which probably launches a couple dozen processes in the background. In any case, you definitely need init (the parent of all the processes) and also a given amount of daemons that are launched by init while booting your system.

At most, you could use "init 1" to go to runlevel 1, which will in turn kill *most* processes. That's the less you will get from a Linux OS while retaining some functionality unless you are ready to write a kernel module that can be used as a shell.

Last edited by i92guboj; 08-03-2010 at 02:06 AM.
 
Old 08-03-2010, 02:35 AM   #5
flores81
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Rep: Reputation: 0
yup, taht's true
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to kill shell window Paris Heng Linux - Software 3 06-11-2009 11:27 AM
Use only one "kill" to kill father and child processes Xosen Programming 7 08-28-2008 03:33 AM
shell script to kill processes running on port number varunbihani Linux - Newbie 13 12-06-2005 08:46 AM
how to use kill to kill a batch of processes with same name? dr_zayus69 Linux - Software 2 09-03-2005 06:35 PM
shell script to kill all processes on specified port varunbihani Linux - General 1 04-19-2005 05:39 AM


All times are GMT -5. The time now is 02:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration