SlideShare a Scribd company logo
1 of 32
6 – Processes
           and Threads


                 Borislav Varadinov
Marian Marinov
                            System
CEO of 1H Ltd.
                      Administrator
mm@1h.com
                   bobi [ at ] itp.bg
What is a Process?
What is a Process?



➢ Single process OS – Arduino
➢ Multy process OS – Any modern kernel
What is a Process?



MEMORY      CPU        I/O




         APPLICATION
Multiple Processes?
MEMORY     MEMORY      CPU             I/O




         APPLICATION         APPLICATION
Multiple Processes?

➢ Segmentation Fault
➢ Bus Error
➢ Access violation

            SEGFAULT/SIGSEGV

➢ Since Linux 3.2
    CROSS MEMORY ATTACH
What is a Thread?
What is a Thread?
MEMORY            CPU             I/O




    Thread0             Thread1


              Process
What is a Thread?
Creating a process
➢ FORK
 ➢ Copy the memory of the parent
 ➢ Inherit FD table
 ➢ Inherit credentials
 ➢ Inherit security
➢ EXEC
 ➢ Create new memory space
 ➢ Inherit FD table
 ➢ Inherit credentials
What is a Thread?
Creating a process
#include <stdio.h>
#include <unistd.h>
int main() {
    int i;
    pid_t p;
    p = fork();
    if (p == 0) {
        for (i=0;i<=3;i++)
             printf("I'm the child(%d)!n", p);
    } else {
        for (i=0;i<=3;i++)
             printf("My child is %dn", p);
    }
    return 0;
}
Creating a process

hackman@terion:~$ ./f
My child is 3721
My child is 3721
My child is 3721
My child is 3721
I'm the child(0)!
I'm the child(0)!
I'm the child(0)!
I'm the child(0)!
hackman@terion:~$
Creating a process
#include <stdio.h>
#include <unistd.h>
int main() {
    int i;
    pid_t p;
    p = fork();
    if (p == 0) {
        for (i=0;i<=3;i++)
             printf("I'm the child(%d)!n", getpid());
    } else {
        for (i=0;i<=3;i++)
             printf("My child is %dn", p);
    }
    printf("This is not good(%d)!n", getpid());
    return 0;
}
Creating a process

hackman@terion:~$ ./f
My child is 3762
My child is 3762
My child is 3762
My child is 3762
This is not good(3761)!
I'm the child(3762)!
I'm the child(3762)!
I'm the child(3762)!
I'm the child(3762)!
This is not good(3762)!
hackman@terion:~$
Creating a process

EXEC functions
   int execl(const char *path, const char *arg, ...);
   int execlp(const char *file, const char *arg, ...);
   int execle(const char *path, const char *arg,
          ..., char * const envp[]);
   int execv(const char *path, char *const argv[]);
   int execvp(const char *file, char *const argv[]);
   int execvpe(const char *file, char *const argv[],
          char *const envp[]);

Exec functions does not return
Creating a process


system() = exec('/bin/sh -c CMD')

Which means:

your process
  - exec /bin/sh
     - exec CMD
Types of processes


➢ Foreground
➢ Background
➢ Daemons
 ➢ co-relation with terminal
Foreground processes

➢ It has access to the terminal's
 ➢ STDIN         –0
 ➢ STDOUT – 1
 ➢ STDERR – 2
➢ It is directly controlled by the user
➢ It is connected to the terminal (text or
graphic)
Background processes

➢ It has access only to the terminal's
 ➢ STDOUT – 1
 ➢ STDERR – 2
➢ It is NOT directly controlled by the user
➢ It is connected to the terminal (text or
graphic)
Daemon processes


➢ Its STDIN/OUT/ERR are redirected to files
➢ It is NOT directly controlled by the user
➢ It is NOT connected to the terminal (text or
graphic)
IPC

➢ FS PIPES
➢ Process PIPES
➢ Unix Domain Socket
➢ Shared Memory SHM (SysV/POSIX)
➢ Message Queues (SysV/POSIX)
➢ Semaphores (SysV/POSIX)
➢ Signals
IPC – process PIPEs

Proc 1


         a = open(PIPE, “r”);
         b = open(PIPE, “w”);


Proc 2


         close(a); close(b);
         a = open(PIPE, “w”);
         b = open(PIPE, “r”);
IPC – Shared Memory

       Proc 1                       SHM

shmid = shmget(IPC_PRIVATE, ...);
mem = shmat(shmid, ...);


        Proc 2


memset(mem, '0', 200);
IPC – Message Queues


                   Proc 1




                       Proc 2
IPC – Semaphores


                   Proc 1




                   Proc 2
IPC – Signals


                Proc 1




                Proc 2
Signals - Kill


                 Proc 1




                 Proc 2
Signals – Signal handlers

Proc 1
                       sig_handler
           main()


         init_some()


         do_some()


         log_some()
Signals – Signal handlers

      Proc 1
                              sig_handler
                  main()


 SIGHUP         init_some()

0 - 255
                do_some()


                log_some()
Processes and Threads
Free Trainings @ Telerik Academy

   C# Programming @ Telerik Academy
    

 Telerik Software Academy

    

 Telerik Academy @ Facebook

    

 Telerik Software Academy Forums

    

More Related Content

What's hot

Leonardo Nve Egea - Playing in a Satellite Environment 1.2
Leonardo Nve Egea - Playing in a Satellite Environment 1.2Leonardo Nve Egea - Playing in a Satellite Environment 1.2
Leonardo Nve Egea - Playing in a Satellite Environment 1.2
Jim Geovedi
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Sockets
elliando dias
 

What's hot (20)

SAS (Secure Active Switch)
SAS (Secure Active Switch)SAS (Secure Active Switch)
SAS (Secure Active Switch)
 
Leonardo Nve Egea - Playing in a Satellite Environment 1.2
Leonardo Nve Egea - Playing in a Satellite Environment 1.2Leonardo Nve Egea - Playing in a Satellite Environment 1.2
Leonardo Nve Egea - Playing in a Satellite Environment 1.2
 
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SPKrzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
 
Cisco CCNA GRE Tunnel Configuration
Cisco CCNA GRE Tunnel ConfigurationCisco CCNA GRE Tunnel Configuration
Cisco CCNA GRE Tunnel Configuration
 
Network sockets
Network socketsNetwork sockets
Network sockets
 
6.Routing
6.Routing6.Routing
6.Routing
 
Networking in linux
Networking in linuxNetworking in linux
Networking in linux
 
How to convert your Linux box into Security Gateway - Part 1
How to convert your Linux box into Security Gateway - Part 1How to convert your Linux box into Security Gateway - Part 1
How to convert your Linux box into Security Gateway - Part 1
 
DNNのモデル特化ハードウェアを生成するオープンソースコンパイラNNgenのデモ
DNNのモデル特化ハードウェアを生成するオープンソースコンパイラNNgenのデモDNNのモデル特化ハードウェアを生成するオープンソースコンパイラNNgenのデモ
DNNのモデル特化ハードウェアを生成するオープンソースコンパイラNNgenのデモ
 
Evaluation of OpenFlow in RB750GL
Evaluation of OpenFlow in RB750GLEvaluation of OpenFlow in RB750GL
Evaluation of OpenFlow in RB750GL
 
Understanding iptables
Understanding iptablesUnderstanding iptables
Understanding iptables
 
Offline bruteforce attack on wi fi protected setup
Offline bruteforce attack on wi fi protected setupOffline bruteforce attack on wi fi protected setup
Offline bruteforce attack on wi fi protected setup
 
Juniper JNCIA – Juniper RIP Route Configuration
Juniper JNCIA – Juniper RIP Route ConfigurationJuniper JNCIA – Juniper RIP Route Configuration
Juniper JNCIA – Juniper RIP Route Configuration
 
Session 3
Session 3Session 3
Session 3
 
Geep networking stack-linuxkernel
Geep networking stack-linuxkernelGeep networking stack-linuxkernel
Geep networking stack-linuxkernel
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Sockets
 
OpenFlow Data Center - A case Study by Pica8
OpenFlow Data Center - A case Study by Pica8OpenFlow Data Center - A case Study by Pica8
OpenFlow Data Center - A case Study by Pica8
 
Cisco CCNA IP SLA with tracking configuration
Cisco CCNA IP SLA  with tracking  configurationCisco CCNA IP SLA  with tracking  configuration
Cisco CCNA IP SLA with tracking configuration
 
IPTables Primer - Part 2
IPTables Primer - Part 2IPTables Primer - Part 2
IPTables Primer - Part 2
 
Npc08
Npc08Npc08
Npc08
 

Viewers also liked (8)

Processes and Thread OS_Tanenbaum_3e
Processes and Thread OS_Tanenbaum_3eProcesses and Thread OS_Tanenbaum_3e
Processes and Thread OS_Tanenbaum_3e
 
7.protocols 2
7.protocols 27.protocols 2
7.protocols 2
 
Race condition
Race conditionRace condition
Race condition
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Interprocess communication
Interprocess communicationInterprocess communication
Interprocess communication
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Op Sy 03 Ch 23
Op Sy 03 Ch 23Op Sy 03 Ch 23
Op Sy 03 Ch 23
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 

Similar to 6. processes and threads

System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
ashukiller7
 

Similar to 6. processes and threads (20)

System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
 
[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis
 
04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptx
 
[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation
 
[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis
 
Lect3 process
Lect3 processLect3 process
Lect3 process
 
Sysprog 11
Sysprog 11Sysprog 11
Sysprog 11
 
[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis
 
Process management
Process managementProcess management
Process management
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge Solution
 
Os lab final
Os lab finalOs lab final
Os lab final
 
Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?
 
Process management
Process managementProcess management
Process management
 
[ROOTCON13] Pilot Study on Semi-Automated Patch Diffing by Applying Machine-L...
[ROOTCON13] Pilot Study on Semi-Automated Patch Diffing by Applying Machine-L...[ROOTCON13] Pilot Study on Semi-Automated Patch Diffing by Applying Machine-L...
[ROOTCON13] Pilot Study on Semi-Automated Patch Diffing by Applying Machine-L...
 
11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt
 
The hangover: A "modern" (?) high performance approach to build an offensive ...
The hangover: A "modern" (?) high performance approach to build an offensive ...The hangover: A "modern" (?) high performance approach to build an offensive ...
The hangover: A "modern" (?) high performance approach to build an offensive ...
 
Kernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easyKernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easy
 
1032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.21032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.2
 
Multiprocessing with python
Multiprocessing with pythonMultiprocessing with python
Multiprocessing with python
 
Alexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for DevelopersAlexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for Developers
 

More from Marian Marinov

More from Marian Marinov (20)

How to implement PassKeys in your application
How to implement PassKeys in your applicationHow to implement PassKeys in your application
How to implement PassKeys in your application
 
Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & Logging
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanisms
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDB
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdf
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home era
 
Managing sysadmins
Managing sysadminsManaging sysadmins
Managing sysadmins
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefs
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storage
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL server
 
Sysadmin vs. dev ops
Sysadmin vs. dev opsSysadmin vs. dev ops
Sysadmin vs. dev ops
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDK
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networks
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automation
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel tracking
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of servers
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

6. processes and threads

  • 1. 6 – Processes and Threads Borislav Varadinov Marian Marinov System CEO of 1H Ltd. Administrator mm@1h.com bobi [ at ] itp.bg
  • 2. What is a Process?
  • 3. What is a Process? ➢ Single process OS – Arduino ➢ Multy process OS – Any modern kernel
  • 4. What is a Process? MEMORY CPU I/O APPLICATION
  • 5. Multiple Processes? MEMORY MEMORY CPU I/O APPLICATION APPLICATION
  • 6. Multiple Processes? ➢ Segmentation Fault ➢ Bus Error ➢ Access violation SEGFAULT/SIGSEGV ➢ Since Linux 3.2 CROSS MEMORY ATTACH
  • 7. What is a Thread?
  • 8. What is a Thread? MEMORY CPU I/O Thread0 Thread1 Process
  • 9. What is a Thread?
  • 10. Creating a process ➢ FORK ➢ Copy the memory of the parent ➢ Inherit FD table ➢ Inherit credentials ➢ Inherit security ➢ EXEC ➢ Create new memory space ➢ Inherit FD table ➢ Inherit credentials
  • 11. What is a Thread?
  • 12. Creating a process #include <stdio.h> #include <unistd.h> int main() { int i; pid_t p; p = fork(); if (p == 0) { for (i=0;i<=3;i++) printf("I'm the child(%d)!n", p); } else { for (i=0;i<=3;i++) printf("My child is %dn", p); } return 0; }
  • 13. Creating a process hackman@terion:~$ ./f My child is 3721 My child is 3721 My child is 3721 My child is 3721 I'm the child(0)! I'm the child(0)! I'm the child(0)! I'm the child(0)! hackman@terion:~$
  • 14. Creating a process #include <stdio.h> #include <unistd.h> int main() { int i; pid_t p; p = fork(); if (p == 0) { for (i=0;i<=3;i++) printf("I'm the child(%d)!n", getpid()); } else { for (i=0;i<=3;i++) printf("My child is %dn", p); } printf("This is not good(%d)!n", getpid()); return 0; }
  • 15. Creating a process hackman@terion:~$ ./f My child is 3762 My child is 3762 My child is 3762 My child is 3762 This is not good(3761)! I'm the child(3762)! I'm the child(3762)! I'm the child(3762)! I'm the child(3762)! This is not good(3762)! hackman@terion:~$
  • 16. Creating a process EXEC functions int execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg, ..., char * const envp[]); int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); int execvpe(const char *file, char *const argv[], char *const envp[]); Exec functions does not return
  • 17. Creating a process system() = exec('/bin/sh -c CMD') Which means: your process - exec /bin/sh - exec CMD
  • 18. Types of processes ➢ Foreground ➢ Background ➢ Daemons ➢ co-relation with terminal
  • 19. Foreground processes ➢ It has access to the terminal's ➢ STDIN –0 ➢ STDOUT – 1 ➢ STDERR – 2 ➢ It is directly controlled by the user ➢ It is connected to the terminal (text or graphic)
  • 20. Background processes ➢ It has access only to the terminal's ➢ STDOUT – 1 ➢ STDERR – 2 ➢ It is NOT directly controlled by the user ➢ It is connected to the terminal (text or graphic)
  • 21. Daemon processes ➢ Its STDIN/OUT/ERR are redirected to files ➢ It is NOT directly controlled by the user ➢ It is NOT connected to the terminal (text or graphic)
  • 22. IPC ➢ FS PIPES ➢ Process PIPES ➢ Unix Domain Socket ➢ Shared Memory SHM (SysV/POSIX) ➢ Message Queues (SysV/POSIX) ➢ Semaphores (SysV/POSIX) ➢ Signals
  • 23. IPC – process PIPEs Proc 1 a = open(PIPE, “r”); b = open(PIPE, “w”); Proc 2 close(a); close(b); a = open(PIPE, “w”); b = open(PIPE, “r”);
  • 24. IPC – Shared Memory Proc 1 SHM shmid = shmget(IPC_PRIVATE, ...); mem = shmat(shmid, ...); Proc 2 memset(mem, '0', 200);
  • 25. IPC – Message Queues Proc 1 Proc 2
  • 26. IPC – Semaphores Proc 1 Proc 2
  • 27. IPC – Signals Proc 1 Proc 2
  • 28. Signals - Kill Proc 1 Proc 2
  • 29. Signals – Signal handlers Proc 1 sig_handler main() init_some() do_some() log_some()
  • 30. Signals – Signal handlers Proc 1 sig_handler main() SIGHUP init_some() 0 - 255 do_some() log_some()
  • 32. Free Trainings @ Telerik Academy  C# Programming @ Telerik Academy   Telerik Software Academy   Telerik Academy @ Facebook   Telerik Software Academy Forums 