Proses PDF (En)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Process Management

● Processor, memory and kernel informations


● Monitoring process
● Killing process
● Foreground and background process

Version 1.0 linuxslides.blogspot.com


Processor informations
Checking our processor clock:
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Pentium(R) 4 CPU 1.80GHz
...

Version 1.0 linuxslides.blogspot.com


Memory informations
Displaying our memory informations:
$ cat /proc/meminfo
MemTotal: 483100 kB
MemFree: 25352 kB
...
More detailed informations:
$ free -m
total used free shared buffers cached
Mem: 471 445 26 0 3 119
-/+ buffers/cache: 322 149
Swap: 996 230 765

GUI based informations:


$ gnome-system-monitor
Version 1.0 linuxslides.blogspot.com
Kernel and hardware info
Check our kernel:
$ uname -a
Linux linuxmint 2.6.24-16-generic ...

$ dmesg | grep Linux


[ 0.000000] Linux version 2.6.24-16-generic ...

Displaying hardware informations:


$ dmesg | less

Displaying PCI hardware info (vga, sound card, etc):


$ lspci

Version 1.0 linuxslides.blogspot.com


Monitoring process
Displaying active processes:
$ ps
PID TTY TIME CMD
9861 pts/0 00:00:00 bash
10157 pts/0 00:00:00 ps

PID: Process identity


TTY: Terminal where the process is running
TIME: Time needed by CPU to complete the process
CMD: The command which is executed

Version 1.0 linuxslides.blogspot.com


Monitoring process
Displaying all active processes:
$ ps a
PID TTY STAT TIME COMMAND
4471 tty3 Ss+ 0:00 /sbin/getty 38400 tty3
4473 tty6 Ss+ 0:00 /sbin/getty 38400 tty6
8408 tty1 Ss+ 0:00 /sbin/getty 38400 tty1
9861 pts/0 Ss 0:00 bash
10158 pts/0 R+ 0:00 ps a

STAT is the status of the process, which are: Uninterruptible


sleep, Running, Interruptible sleep, Stopped, session leader,
foreground, etc. Further info see chapter PROCESS STATE
CODES in ps manual.

Version 1.0 linuxslides.blogspot.com


Monitoring process
Displaying all active processes from all user:
$ ps au
USER PID %CPU %MEM VSZ RSS TTY STAT START ...
root 4471 0.0 0.0 716 424 tty3 Ss+ 08:14
root 4473 0.0 0.0 716 424 tty6 Ss+ 08:14
root 8408 0.0 0.0 716 424 tty1 Ss+ 08:14
joni 9861 0.0 0.0 716 424 pts/0 Ss 11:07
joni 10158 0.0 0.0 716 424 pts/0 R+ 11:07

USER : user name who run the process


%CPU/MEM: percentage CPU/MEM used by process
VSZ : virtual memory size of the process in KB
RSS : resident set size, RAM used in KB
START : the time process start
Version 1.0 linuxslides.blogspot.com
Monitoring process
Displaying all active processes from all user including non-tty:
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START ...
root 4471 0.0 0.0 716 424 tty3 Ss+ 08:14
root 4473 0.0 0.0 716 424 tty6 Ss+ 08:14
root 8408 0.0 0.0 716 424 tty1 Ss+ 08:14
root 8438 0.0 0.0 716 424 ? Ss 08:14
root 8439 0.0 0.0 716 424 ? Ss 08:14
root 8440 0.0 0.0 716 424 ? Ss 08:14
joni 9861 0.0 0.0 716 424 pts/0 Ss 11:07
joni 10158 0.0 0.0 716 424 pts/0 R+ 11:07

Displaying process which is not associated or executed from a


terminal, such as init process, daemon, etc.
Version 1.0 linuxslides.blogspot.com
Display a tree of processes
$ pstree -p | less
init(1)─┬─NetworkManager(4864)───{NetworkManager}(5045)
├─NetworkManagerD(4878)
├─acpid(4646)
├─apache2(8271)─┬─apache2(8321)
│ ├─apache2(8323)
│ ├─apache2(8324)

Process tree often needed when we have to terminate a parent


process, because the child process is unable to kill.

Version 1.0 linuxslides.blogspot.com


Monitoring process real time
$ top

Version 1.0 linuxslides.blogspot.com


Terminating (kill) process

Use the PID to kill a process:


$ kill <PID>
$ kill 8710

If command above failed, use option “-9”:


$ kill -9 8710

LAB:
Open new terminal in Desktop and type gedit command. Try to find
the terminal's PID (not gedit PID) and kill. Make sure the terminal
and gedit terminated properly.

Version 1.0 linuxslides.blogspot.com


Foreground process

Process 1 Process 2 Process 3

Background process

Process 1 Foreground process run


sequentially, when
Process 2 background process run
simultaneously.

Process 3

Version 1.0 linuxslides.blogspot.com


Foreground and background

Sample of foreground process:


$ find / -name xyz > result.txt 2>&1

We have to wait until process above finished, then we can run


another process:
$ ls -l

Sample of background process:


$ find / -name xyz > result.txt 2>&1 &

At the same time, we can run another process directly:


$ ls -l

Version 1.0 linuxslides.blogspot.com


Change foreground to background
Changing foreground process to background:
$ find / -name xyz > result.txt 2>&1
Ctrl+Z
[1]+ Stopped find / -name xyz > result.txt 2>&1

To see pending/paused process:


$ jobs
[1]+ Stopped find / -name xyz > result.txt 2>&1

Change process number 1 to background:


$ bg 1
Check again with jobs:
$ jobs

Version 1.0 linuxslides.blogspot.com


Change background to foreground
Changing background process to foreground:
$ find / -name xyz > result.txt 2>&1 &

To see background process:


$ jobs
[1]+ Running find / -name xyz > result.txt 2>&1 &

Change process number 1 to foreground:


$ fg 1
Or if it the only one:
$ fg

Version 1.0 linuxslides.blogspot.com

You might also like