UNIX Commands

Kill 

[ # vi  /user/include/bits/signum.h]

Terminate a process

Kill      [-s signal 1     -p ]   [-a]   [--] p id…….

Kill     – l [signal]

The command kill sends the specified signal to the specified process or process group. If no signal is specified the TERM signal is sent . TERM signal will kill process, when don’t catch signal . for other process , it may be necessary to use KILL (9) signal.  Since this signal can not be caught.

Most modern shells have a buittin kill function  , with a usage  rather similar to that of the command described here. The ‘- a’ and ‘- p’ options , and the possibility to specify p ids by command name is local extension.

 

 

 

 

#defineSIGUP1 / * Hang ap (POSIx) */
#defineSIGINT2/ * Interrupt  (ANSI) */
#defineSIGQUIT3/ * Quit (POSIx) */  (ctrl + 1)
#defineSIGILL4/ * Illegal instruction(ANSI) */
#defineSIGTRAP5/ * TRACE trap (POSIx) */
#defineSIGABRT6/ * Abort(ANSI) */
#defineSIGIDT6/ * IDT trap(4.2 BSD) */
#defineSIGBUS7/ * Bus Error (4.2 BSD)  */
#defineSIGFPE8/*Floating – point Exception (ANSI) * /
#defineSIGXILL9/* Kill , un blockable (POSI x) * /
#defineSIGUSR 110/* user= defined signal 1(posi X)
#DefineSIGSEGV11/* segmentation violation(ANSI)*/
#DefineSIGUSR 212/* user – defined signal 2(posi X)
#defineSIGPIPE13/* Broken pipe(posi X)*/
#DefineSIGALRM14/* Alarm clock*/
#DefineSIGTERM15/* Termination (ANSI)*/
#DefineSIG8 Tk FLT16/* Stack fault*/
#DefineSIG CLDSIGCLD/*same as SIGHLD (system V)*/
#DefineSIGCHLD17/*Child status has changed(POSI x)*/
#DefineSIGCONT18/*continue (POSIX )*/
#DefineSIGSTOP(ctrl+z)19/*stop, un blockable(POSI X)*/
#DefineSIG T STP20/*Key board stop(POSIX)*/
#DefineSIG TTIN21/* Background read from tty (POSI X)*/
#DefineSIGTTOU22/*Background write to tty*/
#DefineSIGURG23/*Urgent condition on socket(4.2  BSD)*/
#defineSIGX CPU24/*CPU limit exceeded(4.2 BSD)*/
#defineSIGX FSZ25/* file size limit exceeded (4.2 BSD)*/
#defineSIGX VT ALRM26/*Virtual alarm clock(4.2 BSD)*/
#defineSIG PROF27/*profiling alarm clock (4.2 BSD)*
#defineSIG WINCH28/* Windows size change (4.3 BSD, SUN)*/
#defineSIGPOLL81G10/*pollable event occurred system*/
#defineSIGX IO29/* I/O now possible (4.2 BSD)*/
#defineSIG PER30/* power failure restart(system v)*/
#defineSIG SYS31/* bad system call*/
#define-NSIG65/* biggest signal number + 1(including real time signal)*/
#defineSIGRT MIN
#defineSIGRT MAX

 

 

 

 

 

# define SIGRTMIN (-libc – current – sigrmin ())

# define SIGRTMAX(-libc – current – sigrmax())

 

/* these are hinders  limits   of the kernel . these values should not be used directly  at user  level  */

 

# define  - -  SIGRTMIN              32

# define  - -  SIGRTMAX             (- NSIG -1 )

Implementation of kill command

 

Terminal  - 1

#  include <stdio.h>

Main ()

{

While  (1)

Print f (“%d \n”, get p id ());

}

 

Terminal  - 2

Vi imp – kill .c

#  include <stdio.h>

Main ( int  argc, char   ** arg V)

{

Int  p id , sig num;

P id = a to I (arg V [1]);

Sig num  = a to I (arg V [2]);

If ((Kill  (p id, signum)) < 0)

Print p error  (“Kill”);

Else

Print f (“Signal % d is sent to % d by % d \n”, sig num , p id, get p id ());

}

 

Output :

In terminal  -1  run the program . it executes infinitely.   EX:- 27247     27247

In terminal  -2   cc  - 0    V kill imp _kill .c

./vkill 27247       19  this interrupt number can be any of valid.

 

Output signal 19 is sent to 27247 by 27297 interrupts 27297 is process id of present process that is in terminal 2

 

Raise

-send a signal to the current process

#include <sign at. h>

Int  raise  (int sig );

-the raise () function sends a signal to the current process . it is equivalent to ,

Kill  (get p id (), sig);

-Return value : ‘0’ on success , non – zero for failure

 

Alarm (2)

-set an alarm clock for delivery of a signal

# include <unistd . h >

Unsigned int alarm  (unsigned int seconds );

Alarm () – arranges for a SIG ALARM signal to be delivered to the process   in seconds second’s.

If seconds is zero , no new alarm () is scheduled.

In any event any previously set alarm () is cancelled. 

 

Returns

Returns number of seconds remaining until any previously scheduled alarm was due to delivered , or zero if the was no previously scheduled alarm.

Sleep () may be implemented using SIGALRM; mixing calls to alarm () and sleep () is a bad idea.