SlideShare a Scribd company logo
1 of 28
LINUX
PROGRAMING
By: Sapthami Chatra
Harshith Raj
OPERATING SYSTEM
A program that acts as an intermediate between the user of the computer and the
computer hardware.
Operating system provides an environment where a user can execute their programs.
OPERATING SYSTEM SERVICES:
• File Management
• I/O Management
• Memory Management
• Device Management
• Resoure Management
• CPU Management
• Hardware Mangement
WHY LINUX?
● Open source
● Cost
● Customization
● Security
● Stability
● Performance
● Compatibility
● Software Availability
Compiling with GCC
The compilers of choice on Linux systems are all part of the GNU Compiler Collection,
usually known as GCC. GCC also include compilers for C, C++,Java, Objective-C,
Fortran, and Chill.
File name-pgm1.c
Let’s begin simple example
#include<stdio.h>
int main(){
printf(“lets begin
linux programingn”);
return 0;
}
Compile this code using gcc:
gcc –c pgm1.c –o pgm1
Output:
Compiling with GCC
Compiling multiple source file:
File name-main.c File name-add.cpp headerfile name-add.h
#include <stdio.h>
#include “add.h”
int main(int argc,char ** argv){
int i,j;
i=atoi(argv[1]);
j=atoi(argv[2]);
printf(“the addition of 2
numbers is %dn”,add(i,j);
return 0;
}
Compilation can be done as:
g++ -c main.c add.cpp –o add
#include<stdio.h>
#include “add.h”
Int add(int i,int j){
return i+j;
}
Int add(int i,int j);
Automating the Process with GNU
Make
EXECUTABLE: Object file 1, Object
file 2
<TAB> commands
Object file 1: Source file 1, Source fil
e 2
<TAB> commands
Object file 2: Source file 2
<TAB> commands
Syntax for make command:
Target : dependencies
commands
Make command:
Consider an example: File name-text_head.h
File name-int_main.c
File name-text_file.c
Using make:
Modify the file-text_file.c:
Clean the object files and executable file name
make command:
● The debugger is the program that we use to figure out why our program isn’t behaving the way we think
it should.
● We can use GDB to step through our code, set breakpoints, and examine the value of local variables.
Compiling with Debugging Information:
make CFLAGS=-g
gcc -g -c main.c
g++ -g -c reciprocal.cpp
g++ -g –-output reciprocal main.o reciprocal.o
Running GDB
You can start up gdb by typing:
% gdb add
When gdb starts up, you should see the GDB prompt:
(gdb)
GNU Debugger
● run our program inside the debugger
● (gdb) run
● (gdb) break main
Gnu Debugger
Starting program: reciprocal Program
received signal SIGSEGV, Segmentation
fault. __strtol_internal (nptr=0x0,
endptr=0x0, base=10, group=0) at
strtol.c:287 287 strtol.c: No such file or
directory. (gdb)
Breakpoint 1 at 0x804862e: file
main.c, line 8.
● (gdb) run 4 5
Starting program:add 4 5
Breakpoint 1, main (argc=2,
argv=0xbffff5e4) at main.c:8 8 i = atoi
(argv[1]);
● (gdb) next
Addition of 2 numbers is 9
● The exit code is a small integer; by convention, an exit code of zero
denotes successful execution, while nonzero exit codes indicate that
an error occurred. Some programs use different nonzero exit code
values to distinguish specific errors.
Program Exit Codes
The Environment
Syntax:
export NAME=value
Some common environment variables are:
Consider an example:
Environment variables:
Step 4: Create static library.
3
2
Static library
Step 1:Create a C file that contains
functions in your library
Step 2:Create a header file for the
library
4
Step 3: Compile library files.
1
Step 1: Create a C file with main
function
Step 2:Compile the driver
program.
Let’s create a program that uses static library
Step 3:Link the compiled driver
program to the static library.
Step 4:Run the driver program
1 2
3 4
● Compile library files: gcc –fpic -c add.c
● Create dynamic library: gcc –shared –o libbasic.so add.o
● Compile the executable file: gcc –c demo.c
● Generate the executable file by linking with the library: gcc –o demo demo.o libbasic.so
Dynamic library:
PROCESS
“Running instance of a program is
called a PROCESS.”
Process v/s Program
 A program is a passive entity, such as file containing a list of
instructions stored on a disk.
 Process is a active entity, with a program counter specifying
the next instruction to execute and a set of associated
resources.
 A program becomes a process when an executable file is
loaded into main memory.
Process - State Transition Diagram
Context switching
Creating Processes
1.Using System
 It creates a sub-process running the standard
shell.
 Hands the command to that shell for execution.
 Because the system function uses a shell to
invoke your command, it's subject to the
features and limitations of the system shell.
 The system function in the standard C library is
used to execute a command from within a
program.
 Much as if the command has been typed into a
shell
#include<stdlib.h>
int main()
{
int return_value;
return_value = system("ls -
l");
return return_value;
}
Creating Processes (cont.)
2.Using Fork and Exec
 Fork makes a child process that is an
exact copy of its parent process.
 When a program calls fork, a duplicate
process, called the child process, is
created.
 The parent process continues executing
the program from the point that fork was
called.
 The child process, too, executes the
same program from the same place.
 All the statements after the call to fork
will be executed twice, once, by the
parent process and once by the child
process
(A)
(B)
Creating Processes (cont.)
Process Scheduling
 Linux schedules the parent and child processes independently; there’s
no guarantee of which one will run first, or how long it will run before
Linux interrupts it and lets the other process (or some other process
on the system) run.
Signals
 A signal is a special message sent to a
process.
 Signals are asynchronous; when a
process receives a signal, it processes
the signal immediately, without finishing
the current function or even the current
line of code.
 There are several dozen different
signals, each with a different meaning.
 Each signal type is specified by its
signal number, but in programs, you
usually refer to a signal by its name.
Process Termination
 When a parent forks a child, the two process can
take any turn to finish themselves and in some
cases the parent may die before the child.
 In some situations, though, it is desirable for the
parent process to wait until one or more child
processes have completed.
 This can be done with the wait() family of system
calls.
 These functions allow you to wait for a process to
finish executing, enable parent process to retrieve
information about its child’s termination
THANK
YOU

More Related Content

Similar to Process (OS),GNU,Introduction to Linux oS

Life of a Chromium Developer
Life of a Chromium DeveloperLife of a Chromium Developer
Life of a Chromium Developermpaproductions
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Annie Huang
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made EasyAlon Fliess
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming Hemantha Kulathilake
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux Mohammad Golyani
 
Golang execution modes
Golang execution modesGolang execution modes
Golang execution modesTing-Li Chou
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Reproducibility in artificial intelligence
Reproducibility in artificial intelligenceReproducibility in artificial intelligence
Reproducibility in artificial intelligenceCarlos Toxtli
 
Devry gsp 215 week 7 i lab networking and a tiny web server new
Devry gsp 215 week 7 i lab networking and a tiny web server newDevry gsp 215 week 7 i lab networking and a tiny web server new
Devry gsp 215 week 7 i lab networking and a tiny web server newwilliamethan912
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005Saleem Ansari
 
Don't Fear the Autotools
Don't Fear the AutotoolsDon't Fear the Autotools
Don't Fear the AutotoolsScott Garman
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 

Similar to Process (OS),GNU,Introduction to Linux oS (20)

lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Life of a Chromium Developer
Life of a Chromium DeveloperLife of a Chromium Developer
Life of a Chromium Developer
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
Autotools
AutotoolsAutotools
Autotools
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux
 
Golang execution modes
Golang execution modesGolang execution modes
Golang execution modes
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Reproducibility in artificial intelligence
Reproducibility in artificial intelligenceReproducibility in artificial intelligence
Reproducibility in artificial intelligence
 
Open MPI
Open MPIOpen MPI
Open MPI
 
Devry gsp 215 week 7 i lab networking and a tiny web server new
Devry gsp 215 week 7 i lab networking and a tiny web server newDevry gsp 215 week 7 i lab networking and a tiny web server new
Devry gsp 215 week 7 i lab networking and a tiny web server new
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005
 
Don't Fear the Autotools
Don't Fear the AutotoolsDon't Fear the Autotools
Don't Fear the Autotools
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
HPC_MPI_CICD.pptx
HPC_MPI_CICD.pptxHPC_MPI_CICD.pptx
HPC_MPI_CICD.pptx
 

Recently uploaded

Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 

Recently uploaded (20)

Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 

Process (OS),GNU,Introduction to Linux oS

  • 2. OPERATING SYSTEM A program that acts as an intermediate between the user of the computer and the computer hardware. Operating system provides an environment where a user can execute their programs. OPERATING SYSTEM SERVICES: • File Management • I/O Management • Memory Management • Device Management • Resoure Management • CPU Management • Hardware Mangement
  • 3. WHY LINUX? ● Open source ● Cost ● Customization ● Security ● Stability ● Performance ● Compatibility ● Software Availability
  • 4. Compiling with GCC The compilers of choice on Linux systems are all part of the GNU Compiler Collection, usually known as GCC. GCC also include compilers for C, C++,Java, Objective-C, Fortran, and Chill. File name-pgm1.c Let’s begin simple example #include<stdio.h> int main(){ printf(“lets begin linux programingn”); return 0; } Compile this code using gcc: gcc –c pgm1.c –o pgm1 Output:
  • 5. Compiling with GCC Compiling multiple source file: File name-main.c File name-add.cpp headerfile name-add.h #include <stdio.h> #include “add.h” int main(int argc,char ** argv){ int i,j; i=atoi(argv[1]); j=atoi(argv[2]); printf(“the addition of 2 numbers is %dn”,add(i,j); return 0; } Compilation can be done as: g++ -c main.c add.cpp –o add #include<stdio.h> #include “add.h” Int add(int i,int j){ return i+j; } Int add(int i,int j);
  • 6. Automating the Process with GNU Make EXECUTABLE: Object file 1, Object file 2 <TAB> commands Object file 1: Source file 1, Source fil e 2 <TAB> commands Object file 2: Source file 2 <TAB> commands Syntax for make command: Target : dependencies commands
  • 7. Make command: Consider an example: File name-text_head.h File name-int_main.c File name-text_file.c Using make:
  • 8. Modify the file-text_file.c: Clean the object files and executable file name make command:
  • 9. ● The debugger is the program that we use to figure out why our program isn’t behaving the way we think it should. ● We can use GDB to step through our code, set breakpoints, and examine the value of local variables. Compiling with Debugging Information: make CFLAGS=-g gcc -g -c main.c g++ -g -c reciprocal.cpp g++ -g –-output reciprocal main.o reciprocal.o Running GDB You can start up gdb by typing: % gdb add When gdb starts up, you should see the GDB prompt: (gdb) GNU Debugger
  • 10. ● run our program inside the debugger ● (gdb) run ● (gdb) break main Gnu Debugger Starting program: reciprocal Program received signal SIGSEGV, Segmentation fault. __strtol_internal (nptr=0x0, endptr=0x0, base=10, group=0) at strtol.c:287 287 strtol.c: No such file or directory. (gdb) Breakpoint 1 at 0x804862e: file main.c, line 8. ● (gdb) run 4 5 Starting program:add 4 5 Breakpoint 1, main (argc=2, argv=0xbffff5e4) at main.c:8 8 i = atoi (argv[1]); ● (gdb) next Addition of 2 numbers is 9
  • 11. ● The exit code is a small integer; by convention, an exit code of zero denotes successful execution, while nonzero exit codes indicate that an error occurred. Some programs use different nonzero exit code values to distinguish specific errors. Program Exit Codes
  • 12. The Environment Syntax: export NAME=value Some common environment variables are:
  • 14. Step 4: Create static library. 3 2 Static library Step 1:Create a C file that contains functions in your library Step 2:Create a header file for the library 4 Step 3: Compile library files. 1
  • 15. Step 1: Create a C file with main function Step 2:Compile the driver program. Let’s create a program that uses static library Step 3:Link the compiled driver program to the static library. Step 4:Run the driver program 1 2 3 4
  • 16. ● Compile library files: gcc –fpic -c add.c ● Create dynamic library: gcc –shared –o libbasic.so add.o ● Compile the executable file: gcc –c demo.c ● Generate the executable file by linking with the library: gcc –o demo demo.o libbasic.so Dynamic library:
  • 18. “Running instance of a program is called a PROCESS.”
  • 19. Process v/s Program  A program is a passive entity, such as file containing a list of instructions stored on a disk.  Process is a active entity, with a program counter specifying the next instruction to execute and a set of associated resources.  A program becomes a process when an executable file is loaded into main memory.
  • 20. Process - State Transition Diagram
  • 22. Creating Processes 1.Using System  It creates a sub-process running the standard shell.  Hands the command to that shell for execution.  Because the system function uses a shell to invoke your command, it's subject to the features and limitations of the system shell.  The system function in the standard C library is used to execute a command from within a program.  Much as if the command has been typed into a shell #include<stdlib.h> int main() { int return_value; return_value = system("ls - l"); return return_value; }
  • 23. Creating Processes (cont.) 2.Using Fork and Exec  Fork makes a child process that is an exact copy of its parent process.  When a program calls fork, a duplicate process, called the child process, is created.  The parent process continues executing the program from the point that fork was called.  The child process, too, executes the same program from the same place.  All the statements after the call to fork will be executed twice, once, by the parent process and once by the child process (A) (B)
  • 25. Process Scheduling  Linux schedules the parent and child processes independently; there’s no guarantee of which one will run first, or how long it will run before Linux interrupts it and lets the other process (or some other process on the system) run.
  • 26. Signals  A signal is a special message sent to a process.  Signals are asynchronous; when a process receives a signal, it processes the signal immediately, without finishing the current function or even the current line of code.  There are several dozen different signals, each with a different meaning.  Each signal type is specified by its signal number, but in programs, you usually refer to a signal by its name.
  • 27. Process Termination  When a parent forks a child, the two process can take any turn to finish themselves and in some cases the parent may die before the child.  In some situations, though, it is desirable for the parent process to wait until one or more child processes have completed.  This can be done with the wait() family of system calls.  These functions allow you to wait for a process to finish executing, enable parent process to retrieve information about its child’s termination