Friday, October 5, 2012

Linux and processes


Process is a instance of a computer program that is been executed. Each porcess have assign resources through operating system such as: processor, memory, access to intput-output devices. This resources are destined only for this process and it isn't share with other processes This is featue which distinguish between processes and threads. To manage the processes is responding a kernel. To create a new process is required to execute a system command fork or his derivative. Each processes have in linux:
- process identifier PID
- parent process identifier PPID
- process name CMD
- user name USER
- process piority queue PRI and NI
To display processes working on computer is command ps with:
-a display processes from all users
-x display list of demons porcess
-l display a additional information about porcess

user:~$ ps -ax
  PID          TTY     STAT      TIME COMMAND
    1 ?       Ss       0:01          /sbin/init
    2 ?       S        0:00          [kthreadd]
    3 ?       S        0:00          [ksoftirqd/0]
                   ...
 2459 ?       S        0:00          gnome-pty-helper
 2461 pts/0   Ss       0:00          bash
 2516 pts/0   R+       0:00          ps -ax

To display dinamic real-time view of runing processes is top command. To display ruining procesess as a tree is pstree command.
First  process who is open on linux is init process with PID=1. It is parent for all other procesess which we call them a child process. Scripts are open through init process and are locate in /etc/init.d and they are usually use to booting computer. Process init may by on varying levels of working wehre:
0 - halt the system
1 - single user mode
2-5- multi user modes
6 - reboot the sytem
To check levels of working we execute command who -r.

user:~$ who -r
run-level 2  2012-10-06 18:44

Init process is also demon process because it don't need interaction with human and run as a backgound peocess. Tradicionally demon names end with letter 'd' for example: ftpd, httpd and so on. To comunication with running process is command kill which send signals. To check what kinds of signals we can send we use kill -l. More ofen than not are ues:
-1  IGHUP read in again configuration file without terninate the process
-2  SIGTERM is default signal and it's sending requst to a process to request its termination and let the process to perform  appropriate termination.
-9  SIGKILL cause terninate immediately
-19 SIGSTOP stop a process for later resumption
-18 SIGCONT restart a process previously paused
To send signals to group of processes with the same name is killall command.

user:~$ sleep 100 &
[1] 2546
user:~$ sleep 200 &
[2] 2547
user :~$ killall sleep
[1]-  Zakończony             sleep 100
[2]+  Zakończony             sleep 200

Zombie proces is that which has compled execution but still has entry in the process table because its parent don't execute its child's exit status.
To change the  process priority we use renice command. To open the program with determining priority process we use nice comand. This commands change NI value which can impact on PRI value. When  NI have less value then have bigger priority.

nice -10 k-meleon

To open any process in the background we can add & on the end of command. Owing to & during working  process in the background we back immediately to the command line.To display process  in the background we use jobs command.

user@K52Je:~$ jobs
[1]-  Running                 sleep 200 &
[2]+  Running                 sleep 100 &

To bring the process back in the foreground we use fg command. To suspend a process we klick Ctrl+Z. We can move back in the bacground using bg command or in the  foregroud using fg command.

user@K52Je:~$ fg 2
sleep 100

No comments:

Post a Comment