際際滷

際際滷Share a Scribd company logo
LinuxFEST 11.10.2008




                  GNU/Linux
                                     Procesy



Autor: Michal Sedl叩k
Email: michal6103 [at] gmail [dot] com
Prezent叩cia je zalo転en叩 na


                            The LBook:
              An Introductory Guide to Linux Basics
             http://linuxbasics.org/course/book/index

       Vizu叩lna t辿ma prezent叩cie je odvoden叩
                  t辿my vytvorenej:
               Sakari Koivunen and Henrik Omma
                Released under the LGPL license.



11.10.2008                                              2/35
Obsah

   
       V邸eobecne o procesoch
            Typy, atrib炭ty, 転ivotn箪 cyklus
   
       Spr叩va procesov
   
       Pl叩novanie procesov
            Sleep, at, cron, crontab




11.10.2008                                    3/35
Program - Proces


  
      Program je pas鱈vny zhluk in邸trukci鱈 v
      strojovo zrozumite直nej forme
         ELF - Executable and Linking Format
  
      Jeden program m担転e sp炭邸泥a泥 viac procesov




11.10.2008                                      4/35
Proces - Vl叩kno


    Proces je vo v邸eobecnosti in邸tancia programu
       Obraz strojov辿ho k坦du (code)
       Naalokovan叩 pam辰泥 (heap, stack)
       Tabu直ka zdrojov (file deskriptory)
       Bezpenostn辿 atrib炭ty (EUID, RUID, EGUI...)
       Stav procesoru (obsah registrov + PC, SP...)

    Vl叩kno je postupnos泥 in邸trukci鱈
       Zdie直a pam辰泥 procesu
       Program Counter, Stack Pointer, Data registers
11.10.2008                                             5/35
Proces - Vl叩kno
      Ka転d箪 proces obsahuje jedno, alebo viac
       vl叩kien
      Ka転d辿 vl叩kno patr鱈 niektor辿mu procesu




11.10.2008                                       6/35
Proces vs. vl叩kno


michal@michal足desktop:~$cattest.py
importtime,threading,processing
forclsin[threading.Thread,processing.Process]:
start=time.time()
for_inrange(1000):
child=cls()
child.start()
child.join()
print'Spawning1000childrenwith%stook%.2fs'%(
cls.__name__,time.time()足start)



michal@ubuntu:~$pythontest.py
Spawning1000childrenwithThreadtook0.19s
Spawning1000childrenwithProcesstook4.76s



11.10.2008                                                  7/35
Typy procesov

   
       Interakt鱈vne procesy
   
       Automatick辿 procesy
   
       禽辿馨看稼庄 (daemons)




11.10.2008                    8/35
Interakt鱈vne procesy

    Inicializovan辿 a ovl叩dan辿 cez termin叩l
        Popredie
          
              Norm叩lne spustenie procesu
          
              Proces pripojen箪 k termin叩lu
          
              Termin叩l posiela pr鱈kazy procesu
        Pozadie
          
              Spustenie so znakom & za pr鱈kazom:      xterm &
          
              Proces sa po inicializ叩ci鱈 odpoj鱈 od termin叩lu
    michal@michal足desktop:~$xterm&
    [1]29611
    michal@michal足desktop:~$jobs
    [1]+Runningxterm&
    michal@michal足desktop:~$
11.10.2008                                                      9/35
Pr叩ca s interakt鱈vnymi
    procesmi
prikaz      Spust鱈 pr鱈kaz v popred鱈
prikaz& Spust鱈 pr鱈kaz na pozad鱈 a uvoln鱈 termin叩l
jobs        Zobraz鱈 procesy be転iace na pozad鱈

 Ctrl+Z      Pozastavenie procesu SIGSTOP (suspend)

 Ctrl+C      Preru邸enie programu v popred鱈 SIGINT
bg          Reaktiv叩cia pozastaven辿ho procesu
fg          Vyvolanie programu do popredia
kill        ukonenie procesu

11.10.2008                                          10/35
Automatick辿 procesy

   
       Nie s炭 pripojen辿 k termin叩lu
   
       Sp炭邸泥an辿 na z叩klade FIFO pr鱈stupu
            at
              
                  Spustenie procesu v konkr辿tnom ase
            batch
              
                  Spustenie procesu ak je za泥a転enie syst辿mu n鱈zke




11.10.2008                                                      11/35
Daemon

   
       Vo v邸eobecnosti inicializovan辿 pri 邸tarte
   
       Procesy spusten辿 nepretr転ite
   
       Serverov辿 aplik叩cie (client-server)
   
       Napr. httpd(Apache), inetd, ftpd




11.10.2008                                         12/35
Atrib炭ty procesov

         Process ID (PID)
         Parent Proces ID (PPID)
         Nice
         Terminal (TTY)
         UID
             
                 Real User Id (RUID)
             
                 Effective User Id (EUID)
         GID
             
                 Real Group Id (RGID)
             
                 Effective Group Id (EGID)
11.10.2008                                   13/35
Parametre procesov


     michal@michal足desktop:~$passwd&
     [1]6129
     [1]+Stoppedpasswd

     michal@michal足desktop:~$ps足axopid,ppid
     ,nice,user,euid,ruid,cmd

     PIDPPIDNIUSEREUIDRUIDCMD
     610659440100010001000bash
     612961060root01000passwd
     613061060100010001000ps

11.10.2008                                        14/35
Inform叩cie o procesoch


                  michal@ubuntu:~$ps
                  PIDTTYTIMECMD
                  6133pts/000:00:00bash
                  6983pts/000:00:00ps


   michal@ubuntu:~$psaux
   USERPID%CPU%MEMVSZRSSTTYSTATSTARTTIMECOMMAND
   root10.00.228441692?Ss21:200:01/sbin/init
   root20.00.000?S<21:200:00[kthreadd]
   root30.00.000?S<21:200:00[ksoftirqd/0]
   root40.00.000?S<21:200:00[watchdog/0]
   root50.00.000?S<21:200:00[events/0]
   root60.00.000?S<21:200:00[khelper]
   ...
   ...
   ...

11.10.2008                                                                15/35
Informacie o procesoch

     michal@ubuntu:~$pstree
     initNetworkManager{NetworkManager}
     NetworkManagerD
     acpid
     atd
     avahi足daemonavahi足daemon
     bonobo足activati{bonobo足activati}
     cron
     cupsd
     dhcdbddhclient
     firefox5*[{firefox}]
     gajim.pysh
     gconfd足2
     gdmgdmXorg
     gnome足sessionbluetooth足apple
     gnome足panel
     metacity
     nautilus{nautilus}
     nm足applet
     python
11.10.2008                                                      16/35
永姻鱈一鉛温糸y
 michal@ubuntu:~$pgrep足umichal
 5749
 5824
 5825
 5828
 .
 .
 .


 michal@ubuntu:~$ps足fp$(pgrepfirefox)
 UIDPIDPPIDCSTIMETTYTIMECMD
 michal70961822:27?00:00:02/usr/lib/firefox足3.0.3/f...


 michal@ubuntu:~$renice+4$(pgrepfirefox)
 7096:oldpriority0,newpriority4


 michal@ubuntu:~$pkillfirefox
 michal@ubuntu:~$killallfirefox
 firefox:noprocesskilled
11.10.2008                                                        17/35
11.10.2008   18/35
11.10.2008   19/35
Vytvorenie procesu
   
       Fork
          Vytvorenie k坦pie procesu
          Zistenie PID (Die泥a泥u sa PID zd叩 by泥 0)
          Vykonanie algoritmu na z叩klade PID
          Nov箪 proces be転鱈 v rovnakom prostred鱈
             
                 Nastavenie I/O, environment variables,...
   
       Exec
          Nahradenie procesu zavolan箪m procesom
          PID sa nemen鱈
          Nahrad鱈 sa stack, heap, data
11.10.2008                                                   20/35
禽辿馨看稼庄
   
       D辿mon m叩 ako PPID 1 (init)
   
       Rodiia d辿monizuj炭 svoje deti, aby deti
       pre転ili po ich smrti
   
       永姻鱈一鉛温糸 - Window manager
            Dok叩転eme zmeni泥 WM bez re邸tartu n鱈m
             spusten箪ch programov




11.10.2008                                         21/35
Ukonenie procesu a zombie


   
       Pri norm叩lnom ukonen鱈 vracia proces
       rodiovi exit status
   
       Zombie  rodi neprebral sign叩l o
       ukonen鱈 procesu
   
       Exit status je 鱈slo
   
       Uvo直nenie zdrojov
   
       Zabitie svojich zombie det鱈

11.10.2008                                    22/35
永姻鱈一鉛温糸y exit k坦dov

michal@michal足desktop:~$ps|grepneexistuje;echo$?
1

michal@michal足desktop:~$ps|grepbash;echo$?
18653pts/000:00:00bash
0

michal@michal足desktop:~$lst*;echo$?
test.pytree.DBFtv.jpg
0

michal@michal足desktop:~$lsneexistuje;echo$?
ls:niejemo転n箪pr鱈stupkasd:Nosuchfileordirectory
2




11.10.2008                                                  23/35
皆庄乙稼叩鉛霞

   
       tandardne ak箪ko直vek sign叩l ukon鱈 proces
   
       Medziprocesov叩 komunik叩cia (IPC)
      kill足l;kill足9足1
   
       15 SIGTERM  Ukonenie procesu
   
       2 SIGINT  Preru邸enie (maskovate直n箪)
   
       9 SIGKILL  Zabitie (nemaskovate直n箪)
      1 SIGHUP  Odpojenie termin叩lu - nohup
      man7signal
11.10.2008                                    24/35
Spr叩va v箪konu procesov

   
       Motiv叩cia - Efekt鱈vne vyu転itie prostriedkov
   
       loha pre administr叩tora
      Prv叩 inform叩cia load

   
       V箪kon
            CPU
            Pam辰泥
            I/O
11.10.2008                                      25/35
load
   
       Po鱈ta v叩転en箪 priemer procesov v stave:
            Running - be転iace
            Runnable  akaj炭ce na CPU
            Uninterruptible sleep  akaj炭ce na I/O
   
       1, 5, 15 min炭t
   
       175% v poslednej min炭te
            V priemere akalo 0,75 procesu
  michal@ubuntu:~$uptime
  19:51:48up1:24,4users,loadaverage:1.75,0.86,0.54


11.10.2008                                                        26/35
o m担転e ovplyvni泥 u転鱈vate直?

   
       Nesp炭邸泥a泥 ni o nie je potrebn辿
            Ve直a premenn箪ch prostredia
            Dlh辿 cesty na vyh直ad叩vanie spustite直n箪ch
             s炭borov
            Addony do window managerov atp.
            Zbyton辿 slu転by (bluetooth, cupsd)
   
       Pou転i泥 programy s men邸ou z叩泥a転ou
            locate namiesto find

11.10.2008                                              27/35
永姻鱈一鉛温糸


   michal@ubuntu:~$timelocate*bash*>output

   real 0m0.526s
   user 0m0.428s
   sys 0m0.024s


   michal@ubuntu:~$timefind/足name*bash*>output

   real 1m11.150s
   user 0m1.152s
   sys 0m3.424s


11.10.2008                                        28/35
Bute mil箪 k in箪m procesom

   
       Upravi泥 prioritu programom
            nice
            renice
   
       Default 0
   
       Kladn辿 hodnoty
   
       Z叩porn辿 hodnoty iba root
   
       Index叩cia beagle, trackerd
   
       Nie je dobr箪 n叩pad zni転ova泥 prioritu
       interakt鱈vnej aplik叩ci鱈
11.10.2008                                    29/35
Pam辰泥 a disk


michal@ubuntu:~$free足m
totalusedfreesharedbufferscached
Mem:7577451202289
足/+buffers/cache:453304
Swap:1027241002



michal@ubuntu:~$vmstat
procs足足足足足足足足memory足足足足足足足足足足足swap足足足io足足足system足足足足足cpu足足足足
rbswpdfreebuffcachesisobiboincsussyidwa
2025532107561156298216142821473211172194734




11.10.2008                                                          30/35
o s u邸etren箪m asom

   
       sleep
   
       at
   
       batch
   
       cron

   $(sleep1800;echoSkoncilocviko)&

   $(nohupsleep5h;nice足30moj_program)&



11.10.2008                                     31/35
at, atrm, atq

   
      Spust鱈 program v danom ase
  michal@ubuntu:~$at22:00
  warning:commandswillbeexecutedusing/bin/sh
  at>echoSpustilsomsa:$(date)>at.txt
  at><EOT>
  job1atFriOct1022:00:002008

  michal@ubuntu:~$catat.txt
  Spustilsomsa:Piokt1022:00:00CEST2008


  michal@ubuntu:~$batch
  warning:commandswillbeexecutedusing/bin/sh
  at>echoSpustilsomsa:$(date)>at.txt
  at><EOT>
  job2atFriOct1022:08:002008

  michal@ubuntu:~$catat.txt
  Spustilsomsa:Piokt1022:14:29CEST2008

11.10.2008                                           32/35
cron

   
       Pl叩nova
   
       /etc/cron.d
      crontab足e (editova泥 v箪hradne cez -e)
      crontab足l
   
       U転ivate直sk辿 crontaby v /var/spool/cron
#/etc/crontab
#mhdommondowusercommand
17*   ***rootcd/&&run足parts足足report/etc/cron.hourly
256   ***root cd/&&run足parts足足report/etc/cron.daily
476   **7root cd/&&run足parts足足report/etc/cron.weekly
526   1**root cd/&&run足parts足足report/etc/cron.monthly
#
11.10.2008                                                       33/35
Zhrnutie

   
       o s炭 procesy a vl叩kna
   
       Typy procesov
   
       貼ivotn箪 cyklus procesu
   
       皆庄乙稼叩鉛霞
   
       Priority
   
       Pl叩novanie



11.10.2008                      34/35
akujem za pozornos泥
             Na pr鱈padn辿 ot叩zky r叩d odpoviem

             michal6103 [at] gmail [dot] com


11.10.2008                                     35/35
Sponzori
Referencie


http://en.wikipedia.org/wiki/Daemon_(computer_software
http://en.wikipedia.org/wiki/Demon
http://www.cyberciti.biz/tips/linux-more-on-user-id-passw
http://www.faqs.org/faqs/unix-faq/faq/part4/section-10.h
http://www.cs.berkeley.edu/~istoica/classes/cs194/05/no
http://en.wikipedia.org/wiki/Vfork
http://en.wikipedia.org/wiki/Exec_(operating_system)
http://en.wikipedia.org/wiki/Fork-exec
http://en.wikipedia.org/wiki/Load_(computing)

More Related Content

Linux: Procesy