SlideShare a Scribd company logo
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
Ad

More Related Content

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

lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
AbdelrahmanElewah1
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
Danielle780357
 
Life of a Chromium Developer
Life of a Chromium DeveloperLife of a Chromium Developer
Life of a Chromium Developer
mpaproductions
 
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 Easy
Alon Fliess
 
Autotools
AutotoolsAutotools
Autotools
Vibha Singh
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
Keroles karam khalil
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
Keroles karam khalil
 
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 modes
Ting-Li Chou
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
NEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
meharikiros2
 
Reproducibility in artificial intelligence
Reproducibility in artificial intelligenceReproducibility in artificial intelligence
Reproducibility in artificial intelligence
Carlos Toxtli
 
Open MPI
Open MPIOpen MPI
Open MPI
Anshul Sharma
 
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
williamethan912
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005
Saleem Ansari
 
Don't Fear the Autotools
Don't Fear the AutotoolsDon't Fear the Autotools
Don't Fear the Autotools
Scott 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).doc
MayurWagh46
 
HPC_MPI_CICD.pptx
HPC_MPI_CICD.pptxHPC_MPI_CICD.pptx
HPC_MPI_CICD.pptx
ObjectAutomation2
 
Life of a Chromium Developer
Life of a Chromium DeveloperLife of a Chromium Developer
Life of a Chromium Developer
mpaproductions
 
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 Easy
Alon 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 modes
Ting-Li Chou
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
NEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
meharikiros2
 
Reproducibility in artificial intelligence
Reproducibility in artificial intelligenceReproducibility in artificial intelligence
Reproducibility in artificial intelligence
Carlos 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 new
williamethan912
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005
Saleem Ansari
 
Don't Fear the Autotools
Don't Fear the AutotoolsDon't Fear the Autotools
Don't Fear the Autotools
Scott 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).doc
MayurWagh46
 

Recently uploaded (20)

acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Ad

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
  翻译: