Subscribe:

Ads 468x60px

Pages

Monday, June 20, 2011

Process Management


Process:
Any application that runs on a Linux system is assigned a process ID or PID. This is a numerical representation of the instance of the application on the system. In most situations this information is only relevant to the system administrator who may have to debug or terminate processes by referencing the PID. Process Management is the series of tasks a System Administrator completes to monitor, manage, and maintain instances of running applications.

Type of Process: 
1. Interactive Process  
2. System Process (daemon)

Interactive Process:
    The processes that are invoked by a user and can interact with the user is called Interactive processes. Interactive processes can be classified into foreground and background processes. Foreground process is the process that you are currently interacting with, and is using the terminal as its stdin (standard input) and stdout (standard output). Background process is not interacting with the user and can be in one of two states – paused or running.

Example of  Interactive process: 
The following example will show how foreground and background processes are running.
1. Logon as root.
# su -

2. Run [cd \]
# cd \

3. Run [vi]
# vi data.txt

4. Press [ctrl + z]. This will pause vi
Ctrl + z

5. Type [jobs]
# job
Notice:  vi is running in the background

7. Type [fg %1]. This will bring the first background process to the foreground.
# fg %1

8. Close vi 
:q

System Process:
The process that runs on Linux is a system process or Daemon (day-mon). Daemon is the term used to refer to process’ that are running on the computer and provide services but do not interact with the console. Most server software is implemented as a daemon. Apache, Samba, and inn are all examples of daemons.

Any process can become a daemon as long as it is run in the background, and does not interact with the user. A simple example using the [gedit] command. This will list all text editor window separately on the computer. This command can be set to run in the background by typing [gedit&], and although technically you have control over the shell prompt, you will be able to do little work as the screen displays the output of the process that you have running in the background. 

Notice: The standard pause (ctrl+z) and kill (ctrl+c) commands.

1. View linux process
Show process launched for the current linux user
$ ps
Show process launched for a linux user
$ ps -u username
View all the running linux process
$ ps aux
To see a process tree
$ pstree
To see the processes in real time

2. Stop temporarily processes
$ bigjob
^Z (CRTL+Z)

To see the stopped linux processes 
$ jobs
   [1]+ Stopped bigjob

Kill an stopped process
$ kill %1
   [1]+ Killed bigjob
Resume the linux process
$ fg 1

3. Foreground and background linux processes
To start a process in  background mode
$ bigjob &

See process
$jobs
  [1]+  Running bigjob

Put it in foreground mode
$fg 1

ps command:
The ps command is the used to manage running processes and can be used for many things including viewing the status of your computer and knowing how well the computer is performing.

Some common ps commands: 
View display currently running process on this terminal.
ps

All current processes on this terminal, by all users.
# ps –a

All processes not assigned to a terminal (daemons).
ps –x 

To get information about all running process
# ps –ag

To kill all process except your shell
# kill 0

Start a process in background
# linux-command &

To get all the details regarding the running process.
# ps aux

To check a particular process.
# ps ax | grep process-name

To see currently running processes and there memory usage.
# top

To see currently running processes in a tree structure.
# pstree 

4 killing linux  processes
·          kill -1 pid.    Restart  the process 
·          kill -9  pid .  kill the process
·          kill -15  pid  End  the process 

System calls used for Process management:
  • Fork () :- Used to create a new process
  • Exec() :- Execute a new program
  • Wait():- wait until the process finishes execution
  • Exit():- Exit from the process
  • Getpid():- get the unique process id of the process
  • Getppid():- get the parent process unique id
  • Nice():- to bias the existing property of process  
Signals:
 Various Signals are:
Signal Name
Number
Description
SIGHUP
1
Hangup (POSIX)
SIGINT
2
Terminal interrupt (ANSI)
SIGQUIT
3
Terminal quit (POSIX)
SIGILL
4
Illegal instruction (ANSI)
SIGTRAP
5
Trace trap (POSIX)
SIGIOT
6
IOT Trap (4.2 BSD)
SIGBUS
7
BUS error (4.2 BSD)
SIGFPE
8
Floating point exception (ANSI)
SIGKILL
9
Kill(can't be caught or ignored) (POSIX)
SIGUSR1
10
User defined signal 1 (POSIX)
SIGSEGV
11
Invalid memory segment access (ANSI)
SIGUSR2
12
User defined signal 2 (POSIX)
SIGPIPE
13
Write on a pipe with no reader, Broken pipe (POSIX)
SIGALRM
14
Alarm clock (POSIX)
SIGTERM
15
Termination (ANSI)
SIGSTKFLT
16
Stack fault
SIGCHLD
17
Child process has stopped or exited, changed (POSIX)
SIGCONT
18
Continue executing, if stopped (POSIX)
SIGSTOP
19
Stop executing(can't be caught or ignored) (POSIX)
SIGTSTP
20
Terminal stop signal (POSIX)
SIGTTIN
21
Background process trying to read, from TTY (POSIX)
SIGTTOU
22
Background process trying to write, to TTY (POSIX)
SIGURG
23
Urgent condition on socket (4.2 BSD)
SIGXCPU
24
CPU limit exceeded (4.2 BSD)
SIGXFSZ
25
File size limit exceeded (4.2 BSD)
SIGVTALRM
26
Virtual alarm clock (4.2 BSD)
SIGPROF
27
Profiling alarm clock (4.2 BSD)
SIGWINCH
28
Window size change (4.3 BSD, Sun)
SIGIO
29
I/O now possible (4.2 BSD)
SIGPWR
30
Power failure restart (System V)

0 comments:

Post a Comment