SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
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)
    –   Bezpečnostné 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:~$ cat test.py 
import time, threading, processing
for cls in [threading.Thread, processing.Process]:
    start = time.time()
    for _ in range(1000):
        child = cls()
        child.start()
        child.join()
    print 'Spawning 1000 children with %s took %.2fs' % (
        cls.__name__, time.time() ­ start)



michal@ubuntu:~$ python test.py 
Spawning 1000 children with Thread took 0.19s
Spawning 1000 children with Process took 4.76s



11.10.2008                                                  7/35
Typy procesov

   ●
       Interaktívne procesy
   ●
       Automatické procesy
   ●
       Démoni (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]+  Running                 xterm &
    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        ukončenie 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]+  Stopped                 passwd

     michal@michal­desktop:~$ ps ­axo pid,ppid
     ,nice,user,euid,ruid,cmd

       PID  PPID  NI USER      EUID  RUID  CMD
      6106  5944   0 1000      1000  1000  bash
      6129  6106   0 root         0  1000  passwd
      6130  6106   0 1000      1000  1000  ps

11.10.2008                                        14/35
Informácie o procesoch


                  michal@ubuntu:~$ ps
                    PID TTY          TIME CMD
                   6133 pts/0    00:00:00 bash
                   6983 pts/0    00:00:00 ps


   michal@ubuntu:~$ ps aux
   USER       PID %CPU %MEM    VSZ   RSS TTY  STAT START   TIME COMMAND
   root         1  0.0  0.2   2844  1692 ?    Ss   21:20   0:01 /sbin/init
   root         2  0.0  0.0      0     0 ?    S<   21:20   0:00 [kthreadd]
   root         3  0.0  0.0      0     0 ?    S<   21:20   0:00 [ksoftirqd/0]
   root         4  0.0  0.0      0     0 ?    S<   21:20   0:00 [watchdog/0]
   root         5  0.0  0.0      0     0 ?    S<   21:20   0:00 [events/0]
   root         6  0.0  0.0      0     0 ?    S<   21:20   0:00 [khelper]
   ...
   ...
   ...

11.10.2008                                                                15/35
Informacie o procesoch

     michal@ubuntu:~$ pstree
     init─┬─NetworkManager───{NetworkManager}
          ├─NetworkManagerD
          ├─acpid
          ├─atd
          ├─avahi­daemon───avahi­daemon
          ├─bonobo­activati───{bonobo­activati}
          ├─cron
          ├─cupsd
          ├─dhcdbd───dhclient
          ├─firefox───5*[{firefox}]
          ├─gajim.py───sh
          ├─gconfd­2
          ├─gdm───gdm─┬─Xorg
          │           └─gnome­session─┬─bluetooth­apple
          │                           ├─gnome­panel
          │                           ├─metacity
          │                           ├─nautilus───{nautilus}
          │                           ├─nm­applet
          │                           ├─python
11.10.2008                                                      16/35
Príklady
 michal@ubuntu:~$ pgrep ­u michal
 5749
 5824
 5825
 5828
 .
 .
 .


 michal@ubuntu:~$ ps ­fp $(pgrep firefox)
 UID     PID  PPID  C STIME TTY TIME CMD
 michal  7096     1  8 22:27 ?   00:00:02 /usr/lib/firefox­3.0.3/f...


 michal@ubuntu:~$ renice +4 $(pgrep firefox)
 7096: old priority 0, new priority 4


 michal@ubuntu:~$ pkill firefox
 michal@ubuntu:~$ killall firefox
 firefox: no process killed
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émoni
   ●
       Démon má ako PPID 1 (init)
   ●
       Rodičia démonizujú svoje deti, aby deti
       prežili po ich smrti
   ●
       Príklad - Window manager
       –     Dokážeme zmeniť WM bez reštartu ním
             spustených programov




11.10.2008                                         21/35
Ukončenie procesu a zombie


   ●
       Pri normálnom ukončení vracia proces
       rodičovi exit status
   ●
       Zombie – rodič neprebral signál o
       ukončení procesu
   ●
       Exit status je číslo
   ●
       Uvoľnenie zdrojov
   ●
       Zabitie svojich zombie detí

11.10.2008                                    22/35
Príklady exit kódov

michal@michal­desktop:~$ ps |grep neexistuje;echo $?
1

michal@michal­desktop:~$ ps |grep bash;echo $?
18653 pts/0    00:00:00 bash
0

michal@michal­desktop:~$ ls t*;echo $?
test.py  tree.DBF  tv.jpg
0

michal@michal­desktop:~$ ls neexistuje;echo $?
ls: nie je možný prístup k asd: No such file or directory
2




11.10.2008                                                  23/35
Signály

   ●
       Štandardne akýkoľvek signál ukončí proces
   ●
       Medziprocesová komunikácia (IPC)
   ●   kill ­l; kill ­9 ­1
   ●
       15 SIGTERM – Ukončenie procesu
   ●
       2 SIGINT – Prerušenie (maskovateľný)
   ●
       9 SIGKILL – Zabitie (nemaskovateľný)
   ●   1 SIGHUP – Odpojenie terminálu - nohup
   ●   man 7 signal
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:48 up  1:24,  4 users,  load average: 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.
       –     Zbytočné služby (bluetooth, cupsd)
   ●
       Použiť programy s menšou záťažou
       –     locate namiesto find

11.10.2008                                              27/35
Príklad


   michal@ubuntu:~$ time locate *bash* > output

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


   michal@ubuntu:~$ time find / ­name *bash* >output

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


11.10.2008                                        28/35
Buďte 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
             total   used   free shared buffers cached
Mem:           757    745     12      0       2    289
­/+ buffers/cache:    453    304
Swap:         1027     24   1002



michal@ubuntu:~$ vmstat 
procs ­­­­­­­­memory­­­­­­­­­­ ­swap ­­­io­­ ­system­ ­­­­cpu­­­­
 r  b   swpd  free buff  cache si so  bi  bo  in   cs us sy id wa
 2  0  25532 10756 1156 298216  1  4 282 147 321 1172 19  4 73  4




11.10.2008                                                          30/35
Čo s ušetreným časom

   ●
       sleep
   ●
       at
   ●
       batch
   ●
       cron

   $(sleep 1800; echo Skoncilo cviko) &

   $(nohup sleep 5h; nice ­30 moj_program) &



11.10.2008                                     31/35
at, atrm, atq

   ●
      Spustí program v danom čase
  michal@ubuntu:~$ at 22:00
  warning: commands will be executed using /bin/sh
  at> echo Spustil som sa: $(date) > at.txt
  at> <EOT>
  job 1 at Fri Oct 10 22:00:00 2008

  michal@ubuntu:~$ cat at.txt 
  Spustil som sa: Pi okt 10 22:00:00 CEST 2008


  michal@ubuntu:~$ batch
  warning: commands will be executed using /bin/sh
  at> echo Spustil som sa: $(date) > at.txt
  at> <EOT>
  job 2 at Fri Oct 10 22:08:00 2008

  michal@ubuntu:~$ cat at.txt 
  Spustil som sa: Pi okt 10 22:14:29 CEST 2008

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
#m h dom mon dow  user command
17 *   *    *   * root cd / && run­parts ­­report /etc/cron.hourly
25 6   *    *   * root cd / && run­parts ­­report /etc/cron.daily
47 6   *    *   7 root cd / && run­parts ­­report /etc/cron.weekly
52 6   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
   ●
       Signály
   ●
       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)

Más contenido relacionado

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Linux: Procesy