UNIT -2  UNIX FILES  Prepared By, Darshan.K.R Lecturer,SJBIT Kengeri,Bangalore
The ANSI/ISO C++ standard Objective:  “ To make writing good programs easier and more pleasant for individual programmer ” 1980’s by  Bjarne Stroustrup  at AT & T Bell Labs ANSI C++ standard developed by  WG21 committee of ISO & ANSI X3J16  in 1994
Difference between ANSI C and C++ All functions must be declared or defined before they can be referenced. int foo(); ANSI C :  int foo(…); C++:  int foo(void); C++ encrypts external function names for type-safe linkage.
The POSIX standards IEEE society in 1980’s formed a special Task Force called POSIX for creating standards for OS interfacing. POSIX.1 :  Basic OS APIs for manipulation of files and processes. POSIX.1b :  Standard APIs for real-time OS interface. It includes Interprocess Communication. POSIX.1c:  Standards for multi-threaded programming interface.
The POSIX standards To ensure a user program confirms to  POSIX.1 standard, #define _POSIX_SOURCE  OR % cc -D_POSIX_SOURCE *.c POSIX.1b standard , _POSIX_C_SOURCE 198808L 199009L 199309L _POSIX_VERSION  in the <unistd.h>
Show Posix Version #define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include <iostream.h> #include <unistd.h> int main() { #ifdef _POSIX_VERSION cout<<“System confirms to POSIX”<<_POSIX_VERSION<<endl; #else cout<<“_POSIX_VERSION is undefined”; #endif return 0; }
The POSIX Environment #include <header_file_name> Each #included file need not be a physical file The /user/include directory does not have to exist. POSIX standards do not mandate that all systems support the concept of  supervisor. Userid of Zero  does not have any special privilege.
The POSIX Feature Test Macros _POSIX_JOB_CONTROL _POSIX_SAVED_IDS _POSIX_CHOWN_RESTRICTED _POSIX_NO_TRUNC _POSIX_VDISABLE
Show test macros #define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include <iostream.h> #include <unistd.h> int main() { #ifdef _POSIX_JOB_CONTROL cout<<“System supports job control\n”; #else cout<<“System does not support job control\n”; #endif }
Limits Checking <limits.h> - has the set of configuration limits _POSIX_CHILD_MAX _POSIX_NAME_MAX _POSIX_PATH_MAX …… .
APIs for configuration limits #include <unistd.h> long sysconf(const int limit_name); long pathconf(const char * pathname, int flimit_name); long fpathconf(const int fdesc, int flimit_name); limit_name  in <unistd.h> has values  _SC_CHILD_MAX _SC_OPEN_MAX…..etc flimit_name  in <unistd.h> has values _PC_PATH_MAX _PC_NAME_MAX
#define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include <stdio.h> #include<iostream.h> #include <unistd.h> int main() { int res; if((res=sysconf(_SC_OPEN_MAX)) == -1) perror(“sysconf”); else cout<<“OPEN_MAX:”<<res<<endl; } Test Config
The POSIX.1 FIPS Standard FIPS: Federal Information Processing Standard POSIX.1 FIPS - Developed by NIST (National Institute of Standard and Technology) _POSIX_JOB_CONTROL _POSIX_SAVED_IDS _POSIX_NO_TRUNC _POSIX_CHOWN_RESTRICTED _POSIX_VDISABLE NGROUP_MAX = 8 Read and write APIs should return the no of bytes after signals. Group ID – Inherit that of the parent
The X/Open Standards X/Open  organization was formed by a group of  European  companies to propose a common OS interface for their computing systems. XPG3 – 1989 XPG4 – 1994 COSE (Common Open software Environment)  formed in 1993 by  HP, IBM, Novell, OSF and Sun Microsystems SPEC 1179 Incorporated in XPG4 as part of X/Open Common  Application Environment
UNIX and POSIX APIs System Calls Determine system Config and user info Files manipulation Process creation and control Interprocess Communication Network Communication
System Calls User mode :  is the normal execution context of any user process. It allows the process to access its process-specific data only. Kernel mode :  Is a protective execution environment that allows a user to access kernels data in a restricted manner. Context switching
The UNIX and POSIX Development Environment <unistd.h> APIs /usr/include/sys headers <stdio.h> -  perror function  -  Called by a user process when API execution fails. It prints the system-defined diagnostic message for any failure. lib.a & lib.so  libsocket.a & libsocket.so –  Socket APIs
API Common Characteristics APIs  - return an integer value indicating the termination status of execution. - return –1 if API execution has failed. - set a global variable errno in <errno.h> - user process can call perror/strerror Error Status Code EACCESS EPERM EIO……etc
Question Bank Give the difference between ANSI C and C++. What are the major differences between ANSI ‘C’ and K & R ‘C’? Explain each with examples. What is POSIX? List few POSIX standards. Name a few POSIX APIs. Give the differences between POSIX and UNIX. Give the different POSIX feature test macros. Explain with a program and also give the output of the program.  Give the prototype and explain with an example the following APIs. sysconf pathconf fpathconf Expand FIPS. Describe the characteristics of POSIX. 1 FIPS standard and X/open standard. What are the different features to be implemented in all FIPS conforming systems? Explain the common characteristics of API and describe the error status codes.

More Related Content

PPT
Unit 1
PPT
Unit 4
PDF
Unix processes
PPT
Unit 6
PPT
Unit 3
PDF
The Ring programming language version 1.3 book - Part 60 of 88
PPT
Unit 5
Unit 1
Unit 4
Unix processes
Unit 6
Unit 3
The Ring programming language version 1.3 book - Part 60 of 88
Unit 5

What's hot (20)

PDF
First session quiz
PDF
Functional Programming with LISP
PDF
C programming session8
PDF
Embedded C - Lecture 4
PPTX
Return oriented programming (ROP)
PPT
Unix file api’s
PPTX
08 - Return Oriented Programming, the chosen one
PPTX
Embedded c programming
PDF
Specialized Compiler for Hash Cracking
PPT
Assembler (2)
PPT
Assembler
PPTX
06 - ELF format, knowing your friend
PPTX
Operating Systems - A Primer
ODP
Runtime Symbol Resolution
PDF
Parallel program design
PDF
Bare metal performance in Elixir
DOCX
Unix system calls
TXT
Msfpayload/Msfencoder cheatsheet
PDF
C programming session10
PDF
4Developers 2018: The turbulent road to byte-addressable storage support at t...
First session quiz
Functional Programming with LISP
C programming session8
Embedded C - Lecture 4
Return oriented programming (ROP)
Unix file api’s
08 - Return Oriented Programming, the chosen one
Embedded c programming
Specialized Compiler for Hash Cracking
Assembler (2)
Assembler
06 - ELF format, knowing your friend
Operating Systems - A Primer
Runtime Symbol Resolution
Parallel program design
Bare metal performance in Elixir
Unix system calls
Msfpayload/Msfencoder cheatsheet
C programming session10
4Developers 2018: The turbulent road to byte-addressable storage support at t...
Ad

Viewers also liked (17)

PDF
Unix system programming
PDF
6th Semester (June; July-2015) Computer Science and Information Science Engin...
PPT
Unit 7
PDF
VTU 6TH SEM CSE COMPUTER NETWORKS 2 SOLVED PAPERS OF JUNE-2013 JUNE-14 & JUNE...
PDF
Usp notes unit6-8
PDF
Prog ii
PDF
CEED Solved Paper
PDF
6th Semester (June; July-2014) Computer Science and Information Science Engin...
PDF
Question bank cn2
PDF
6th semester Computer Science and Information Science Engg (2013 December) Qu...
PDF
unix interprocess communication
PPTX
IMM Module 2 - VTU MBA
PDF
Part 03 File System Implementation in Linux
PDF
6th Semester CS / IS (2013-June) Question Papers
PPTX
System calls
PPT
Chapter 1 - Management and Entrepreneurship
 
PPTX
Unix operating system
Unix system programming
6th Semester (June; July-2015) Computer Science and Information Science Engin...
Unit 7
VTU 6TH SEM CSE COMPUTER NETWORKS 2 SOLVED PAPERS OF JUNE-2013 JUNE-14 & JUNE...
Usp notes unit6-8
Prog ii
CEED Solved Paper
6th Semester (June; July-2014) Computer Science and Information Science Engin...
Question bank cn2
6th semester Computer Science and Information Science Engg (2013 December) Qu...
unix interprocess communication
IMM Module 2 - VTU MBA
Part 03 File System Implementation in Linux
6th Semester CS / IS (2013-June) Question Papers
System calls
Chapter 1 - Management and Entrepreneurship
 
Unix operating system
Ad

Similar to Unit 2 (20)

PDF
Usp notes
PDF
2010 JNUG BoF
PPTX
IEEE Posix Standards
PDF
Lecture2 process structure and programming
PDF
Mc7404 np final
PDF
System Programming - Interprocess communication
PPTX
session 4(system calls).pptxsession 4(system calls).pptx
PPTX
Systemcall1
DOCX
Linux 系統程式--第一章 i/o 函式
PPTX
System call
PDF
Systems Programming Assignment Help - Processes
PPT
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
PPT
02 fundamentals
PPT
Linux basics
PDF
Os lab final
PPTX
ch 7 POSIX.pptx
PPTX
Linux System Programming - File I/O
PPT
ch2_OS Structures.ppt To discuss the various ways of structuring an operatin...
PPTX
Services and system calls
Usp notes
2010 JNUG BoF
IEEE Posix Standards
Lecture2 process structure and programming
Mc7404 np final
System Programming - Interprocess communication
session 4(system calls).pptxsession 4(system calls).pptx
Systemcall1
Linux 系統程式--第一章 i/o 函式
System call
Systems Programming Assignment Help - Processes
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
02 fundamentals
Linux basics
Os lab final
ch 7 POSIX.pptx
Linux System Programming - File I/O
ch2_OS Structures.ppt To discuss the various ways of structuring an operatin...
Services and system calls

Recently uploaded (20)

PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPT
What is a Computer? Input Devices /output devices
PDF
Architecture types and enterprise applications.pdf
PDF
August Patch Tuesday
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
Modernising the Digital Integration Hub
PDF
Five Habits of High-Impact Board Members
PDF
Hindi spoken digit analysis for native and non-native speakers
PPT
Geologic Time for studying geology for geologist
O2C Customer Invoices to Receipt V15A.pptx
DP Operators-handbook-extract for the Mautical Institute
NewMind AI Weekly Chronicles – August ’25 Week III
Web Crawler for Trend Tracking Gen Z Insights.pptx
What is a Computer? Input Devices /output devices
Architecture types and enterprise applications.pdf
August Patch Tuesday
Final SEM Unit 1 for mit wpu at pune .pptx
Getting started with AI Agents and Multi-Agent Systems
WOOl fibre morphology and structure.pdf for textiles
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
A comparative study of natural language inference in Swahili using monolingua...
A review of recent deep learning applications in wood surface defect identifi...
1 - Historical Antecedents, Social Consideration.pdf
Benefits of Physical activity for teenagers.pptx
Modernising the Digital Integration Hub
Five Habits of High-Impact Board Members
Hindi spoken digit analysis for native and non-native speakers
Geologic Time for studying geology for geologist

Unit 2

  • 1. UNIT -2 UNIX FILES Prepared By, Darshan.K.R Lecturer,SJBIT Kengeri,Bangalore
  • 2. The ANSI/ISO C++ standard Objective: “ To make writing good programs easier and more pleasant for individual programmer ” 1980’s by Bjarne Stroustrup at AT & T Bell Labs ANSI C++ standard developed by WG21 committee of ISO & ANSI X3J16 in 1994
  • 3. Difference between ANSI C and C++ All functions must be declared or defined before they can be referenced. int foo(); ANSI C : int foo(…); C++: int foo(void); C++ encrypts external function names for type-safe linkage.
  • 4. The POSIX standards IEEE society in 1980’s formed a special Task Force called POSIX for creating standards for OS interfacing. POSIX.1 : Basic OS APIs for manipulation of files and processes. POSIX.1b : Standard APIs for real-time OS interface. It includes Interprocess Communication. POSIX.1c: Standards for multi-threaded programming interface.
  • 5. The POSIX standards To ensure a user program confirms to POSIX.1 standard, #define _POSIX_SOURCE OR % cc -D_POSIX_SOURCE *.c POSIX.1b standard , _POSIX_C_SOURCE 198808L 199009L 199309L _POSIX_VERSION in the <unistd.h>
  • 6. Show Posix Version #define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include <iostream.h> #include <unistd.h> int main() { #ifdef _POSIX_VERSION cout<<“System confirms to POSIX”<<_POSIX_VERSION<<endl; #else cout<<“_POSIX_VERSION is undefined”; #endif return 0; }
  • 7. The POSIX Environment #include <header_file_name> Each #included file need not be a physical file The /user/include directory does not have to exist. POSIX standards do not mandate that all systems support the concept of supervisor. Userid of Zero does not have any special privilege.
  • 8. The POSIX Feature Test Macros _POSIX_JOB_CONTROL _POSIX_SAVED_IDS _POSIX_CHOWN_RESTRICTED _POSIX_NO_TRUNC _POSIX_VDISABLE
  • 9. Show test macros #define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include <iostream.h> #include <unistd.h> int main() { #ifdef _POSIX_JOB_CONTROL cout<<“System supports job control\n”; #else cout<<“System does not support job control\n”; #endif }
  • 10. Limits Checking <limits.h> - has the set of configuration limits _POSIX_CHILD_MAX _POSIX_NAME_MAX _POSIX_PATH_MAX …… .
  • 11. APIs for configuration limits #include <unistd.h> long sysconf(const int limit_name); long pathconf(const char * pathname, int flimit_name); long fpathconf(const int fdesc, int flimit_name); limit_name in <unistd.h> has values _SC_CHILD_MAX _SC_OPEN_MAX…..etc flimit_name in <unistd.h> has values _PC_PATH_MAX _PC_NAME_MAX
  • 12. #define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include <stdio.h> #include<iostream.h> #include <unistd.h> int main() { int res; if((res=sysconf(_SC_OPEN_MAX)) == -1) perror(“sysconf”); else cout<<“OPEN_MAX:”<<res<<endl; } Test Config
  • 13. The POSIX.1 FIPS Standard FIPS: Federal Information Processing Standard POSIX.1 FIPS - Developed by NIST (National Institute of Standard and Technology) _POSIX_JOB_CONTROL _POSIX_SAVED_IDS _POSIX_NO_TRUNC _POSIX_CHOWN_RESTRICTED _POSIX_VDISABLE NGROUP_MAX = 8 Read and write APIs should return the no of bytes after signals. Group ID – Inherit that of the parent
  • 14. The X/Open Standards X/Open organization was formed by a group of European companies to propose a common OS interface for their computing systems. XPG3 – 1989 XPG4 – 1994 COSE (Common Open software Environment) formed in 1993 by HP, IBM, Novell, OSF and Sun Microsystems SPEC 1179 Incorporated in XPG4 as part of X/Open Common Application Environment
  • 15. UNIX and POSIX APIs System Calls Determine system Config and user info Files manipulation Process creation and control Interprocess Communication Network Communication
  • 16. System Calls User mode : is the normal execution context of any user process. It allows the process to access its process-specific data only. Kernel mode : Is a protective execution environment that allows a user to access kernels data in a restricted manner. Context switching
  • 17. The UNIX and POSIX Development Environment <unistd.h> APIs /usr/include/sys headers <stdio.h> - perror function - Called by a user process when API execution fails. It prints the system-defined diagnostic message for any failure. lib.a & lib.so libsocket.a & libsocket.so – Socket APIs
  • 18. API Common Characteristics APIs - return an integer value indicating the termination status of execution. - return –1 if API execution has failed. - set a global variable errno in <errno.h> - user process can call perror/strerror Error Status Code EACCESS EPERM EIO……etc
  • 19. Question Bank Give the difference between ANSI C and C++. What are the major differences between ANSI ‘C’ and K & R ‘C’? Explain each with examples. What is POSIX? List few POSIX standards. Name a few POSIX APIs. Give the differences between POSIX and UNIX. Give the different POSIX feature test macros. Explain with a program and also give the output of the program. Give the prototype and explain with an example the following APIs. sysconf pathconf fpathconf Expand FIPS. Describe the characteristics of POSIX. 1 FIPS standard and X/open standard. What are the different features to be implemented in all FIPS conforming systems? Explain the common characteristics of API and describe the error status codes.