LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 11-03-2009, 01:48 AM   #1
rockingb4u
LQ Newbie
 
Registered: Nov 2009
Posts: 16

Rep: Reputation: 0
internal working of kill command


i am working on kill command in linux,so i want to know how it works when it is called to kill some process,
how process is assigned with pid and which file of process does kill attacks to terminate it
 
Old 11-03-2009, 01:57 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Have you looked at the man page?

Code:
man kill
kill doesn't attack a file it sends a signal to the running process based on the process id that you supply to kill.
 
Old 11-03-2009, 02:51 AM   #3
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Kill is a kernel based command. It tells the Linux kernel to terminate a certain process, based on pid. If you want to know exactly how the program works, there are some good books written about the Linux kernel internals. One of them is called, "Inside The Linux Kernel".
 
Old 11-03-2009, 10:16 AM   #4
rockingb4u
LQ Newbie
 
Registered: Nov 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by AwesomeMachine View Post
Kill is a kernel based command. It tells the Linux kernel to terminate a certain process, based on pid. If you want to know exactly how the program works, there are some good books written about the Linux kernel internals. One of them is called, "Inside The Linux Kernel".
how a process gets a pid no and who assign it and if i m shutting down my pc by a command init 6 then a command killall comes,can i shut down my pc without using killall command and how
 
Old 11-03-2009, 10:38 AM   #5
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
What ever command you use to shutdown a system will generate a killall command as all processes need to be stopped before the system completely shuts itself down.

When a process starts it's assign a process ID via the system/kernel, you can find out the process ids currently active from the command 'ps aux' this will generate alot of output if you have alot of commands however so best used with the grep command but it's worth noting this command will display the grep process itself on top of what you are searching for.
 
Old 11-03-2009, 10:56 AM   #6
rockingb4u
LQ Newbie
 
Registered: Nov 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by r3sistance View Post
What ever command you use to shutdown a system will generate a killall command as all processes need to be stopped before the system completely shuts itself down.

When a process starts it's assign a process ID via the system/kernel, you can find out the process ids currently active from the command 'ps aux' this will generate alot of output if you have alot of commands however so best used with the grep command but it's worth noting this command will display the grep process itself on top of what you are searching for.
i want to kill some process,so can u suggest me that i should use the kill command login as root or i should make a user,i just want to check it
 
Old 11-03-2009, 01:07 PM   #7
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
A normal user can kill the processes they own. A root user can kill any process. For example, if I do ps aux now, I get
Code:
$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
tw296     1723  0.0  0.1   3376   804 ?        Ss   16:13   0:00 /usr/sbin/famd
mpd       1733  2.9  2.2  55780 11508 ?        Ssl  16:13   4:52 /usr/bin/mpd /e
root      1745  0.0  0.9   8608  4804 ?        Ss   16:13   0:06 /usr/bin/slim
root      1747  4.8 11.0  66460 56624 tty7     Rs+  16:13   7:57 /usr/bin/X -nol
tw296     1784 10.8 19.8 303296 101792 ?       Sl   16:13  17:46 firefox
tw296     1795  0.5  4.7  54520 24548 ?        S    16:14   0:57 pidgin
tw296     2301  6.0  1.8  26556  9432 ?        S    18:57   0:00 lxterminal
(note that that output has been drastically trimmed, the whole thing is very long with many processes)

Logged in as tw296, I could stop pidgin with 'kill 1795', but I wouldn't be able to stop X with 'kill 1747', or mpd (a music player daemon) with 'kill 1733'. To kill mpd I could log in as mpd, to kill X I would have to log in as root, and could then kill pidgin, mpd, X, firefox, whatever.

Also, the kill command doesn't just kill things. It sends what are called signals to processes. The default is signal 15, TERM, which asks the process to quit. Some processes will autsave before quitting that way, while a totally nonresponsive process won't quit at all. 'kill -9' will send signal 9, KILL, which ends the process immediately.

The 'killall' command in Linux does not kill everything. In Linux killall kills processes by name, for example 'killall pidgin' would kill pidgin in the example above - in the event that two instances of pidgin were running it would kill them both.
 
Old 11-03-2009, 01:46 PM   #8
rockingb4u
LQ Newbie
 
Registered: Nov 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by cantab View Post
A normal user can kill the processes they own. A root user can kill any process. For example, if I do ps aux now, I get
Code:
$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
tw296     1723  0.0  0.1   3376   804 ?        Ss   16:13   0:00 /usr/sbin/famd
mpd       1733  2.9  2.2  55780 11508 ?        Ssl  16:13   4:52 /usr/bin/mpd /e
root      1745  0.0  0.9   8608  4804 ?        Ss   16:13   0:06 /usr/bin/slim
root      1747  4.8 11.0  66460 56624 tty7     Rs+  16:13   7:57 /usr/bin/X -nol
tw296     1784 10.8 19.8 303296 101792 ?       Sl   16:13  17:46 firefox
tw296     1795  0.5  4.7  54520 24548 ?        S    16:14   0:57 pidgin
tw296     2301  6.0  1.8  26556  9432 ?        S    18:57   0:00 lxterminal
(note that that output has been drastically trimmed, the whole thing is very long with many processes)

Logged in as tw296, I could stop pidgin with 'kill 1795', but I wouldn't be able to stop X with 'kill 1747', or mpd (a music player daemon) with 'kill 1733'. To kill mpd I could log in as mpd, to kill X I would have to log in as root, and could then kill pidgin, mpd, X, firefox, whatever.

Also, the kill command doesn't just kill things. It sends what are called signals to processes. The default is signal 15, TERM, which asks the process to quit. Some processes will autsave before quitting that way, while a totally nonresponsive process won't quit at all. 'kill -9' will send signal 9, KILL, which ends the process immediately.

The 'killall' command in Linux does not kill everything. In Linux killall kills processes by name, for example 'killall pidgin' would kill pidgin in the example above - in the event that two instances of pidgin were running it would kill them both.
i have seen the surce code of kill command in c++,is there any source code in java and if i want to change the working of kill command or some more implementation i have to do ,so i have to do some changes in coding...sugest me
 
Old 11-03-2009, 05:59 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Kernels & OSes generally are written in C and/or C++ (& assembler). Java requires JVM to run, so it can't be the OS itself.
 
Old 11-04-2009, 04:06 AM   #10
rockingb4u
LQ Newbie
 
Registered: Nov 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
Kernels & OSes generally are written in C and/or C++ (& assembler). Java requires JVM to run, so it can't be the OS itself.
if i m installing something in linux,so by ps aux i will know its pid no after that if i m running that process and by using the kill command i dont want to terminate it but pause it for sometime and then resume it...
what are the commands for this and how it will works
 
Old 11-04-2009, 10:21 AM   #11
rockingb4u
LQ Newbie
 
Registered: Nov 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rockingb4u View Post
i am working on kill command in linux,so i want to know how it works when it is called to kill some process,
how process is assigned with pid and which file of process does kill attacks to terminate it
when process runs it provide with pid no by kernel,if i want dat it does not terminate it but pause for sometime and after that resume it....suggest me some commands for it....
 
Old 11-04-2009, 11:20 AM   #12
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
You send it the STOP signal, using kill.

http://tombuntu.com/index.php/2007/1...linux-process/
 
Old 11-05-2009, 04:07 AM   #13
rockingb4u
LQ Newbie
 
Registered: Nov 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by cantab View Post
You send it the STOP signal, using kill.

http://tombuntu.com/index.php/2007/1...linux-process/
if i m installing gcc, while installing in the middle can i pause it for sometime using kill stop command and how many files it download and after viewing resume it......
 
Old 11-07-2009, 05:59 AM   #14
rockingb4u
LQ Newbie
 
Registered: Nov 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by cantab View Post
You send it the STOP signal, using kill.

http://tombuntu.com/index.php/2007/1...linux-process/
if i am transferring data from one pc to other pc through command scp,then
how we will pause the transferring in between ,so that i can see how much data is transfered....can we pause it through kill command and if not..suggest me the command
 
Old 11-07-2009, 09:16 AM   #15
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
Quote:
Originally Posted by rockingb4u View Post
if i m installing gcc, while installing in the middle can i pause it for sometime using kill stop command and how many files it download and after viewing resume it......
The kill command would not details like how many files it has downloaded. Kill simply sends a signal to the running program.

What exactly are you trying to accomplish by reworking the kill command? It's possible that there may be an application that already has the functionality that you require.
 
  


Reply



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
kill command pulkitbajar Linux - Newbie 7 05-12-2009 07:19 PM
why we cannot kill process id 1 with command "kill -9 1" satyaredhat Linux - Newbie 7 03-11-2009 12:48 PM
kill command micro_xii Linux - Newbie 4 11-24-2006 08:48 AM
Kill command could not kill Kanaflloric Linux - General 11 08-22-2005 07:18 AM
The kill command tearinox Linux - Newbie 2 08-15-2003 04:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:42 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
Open Source Consulting | Domain Registration