- Operating Systems Basics
- Operating System (OS) Home
- Operating System Basics
- What is an Operating System
- History of Operating System
- Mainframe Operating System
- Server Operating System
- Multiprocessor Operating System
- Personal Computer OS
- Real-Time Operating System
- Embedded Operating System
- Smart Card Operating System
- OS Processors
- OS Memory
- OS System Calls
- Operating System Structure
- OS Processes and Threads
- OS Processes
- OS Process Model
- OS Process Creation
- OS Process Termination
- OS Process Hierarchies
- OS Process States
- OS Process Implementation
- OS Threads
- OS Thread Model
- OS Thread Implementation
- OS Pop-up Threads
- OS Interprocess Communication
- OS Scheduling
- OS Thread Scheduling
- OS Deadlocks
- OS Deadlocks
- OS Deadlock Resources
- OS Deadlock Conditions
- OS Deadlock Modelling
- OS Deadlock Detection
- OS Deadlock Recovery
- OS Deadlock Avoidance
- OS Deadlock Prevention
- OS Two-Phase Locking
- OS Memory Management
- OS Memory Management
- OS Monoprogramming
- OS Multiprogramming
- OS Relocation and Protection
- Memory Management with Bitmap
- Memory Management with Linked List
- OS Virtual Memory
- OS Page Replacement Algorithms
- OS Local vs Global Allocation Policie
- OS Load Control
- OS Page Size
- OS Separate Instruction & Data Space
- OS Shared Pages
- OS Cleaning Policies
- OS Virtual Memory Interface
- OS Implementation Issues
- OS Involvement with Paging
- OS Page Fault Handling
- OS Instruction Backup
- OS Locking Pages in Memory
- OS Backing Store
- OS Separation of Policy & Mechanism
- OS Segmentation
- Operating System Input/Output
- Operating System Input/Output
- OS Input/Output Devices
- OS Device Controllers
- OS Memory-Mapped Input/Output
- OS Direct Memory Access DMA
- OS Input/Output Software Goals
- OS Programmed Input/Output
- OS Interrupt-Driven Input/Output
- OS Input/Output using DMA
- OS Input/Output Software Layers
- OS Disks
- OS Disk Hardware
- OS Disk Formatting
- OS Stable Storage
- OS Clocks
- OS Character-Oriented Terminals
- OS RS-232 Terminal Hardware
- OS Graphical User Interfaces
- OS Network Terminals
- OS Power Management
- OS File Systems
- OS Files
- OS File Naming
- OS File Structure
- OS File Types
- OS File Access
- OS File Attributes
- OS File Operations
- OS Memory-Mapped Files
- OS Directories
- OS Single-Level Directory System
- OS Two-Level Directory System
- OS Hierarchical Directory System
- OS Path Names
- OS Directory Operations
- OS File System Implementation
- OS File System Layout
- OS Disk Space Management
- Multimedia Operating System
- Multimedia Operating System
- OS Multimedia Files
- OS Audio Encoding
- OS Video Encoding
- OS Video Compression
- OS Multimedia Process Scheduling
- OS Multimedia File System Paradigm
- OS File Placement
- OS Caching
- OS Disk Scheduling
- OS Multiple Processor System
- OS Multiprocessors
- OS Multiprocessor Hardware
- OS Multiprocessor Synchronization
- OS Multiprocessor Scheduling
- OS Multicomputers
- OS Multicomputer Hardware
- Low-Level Communication Software
- User-Level Communication Software
- OS Remote Procedure Call
- OS Distributed Shared Memory
- OS Multicomputer Scheduling
- OS Load Balancing
- OS Distributed System
- OS Network Hardware
- OS Network Services and Protocols
- OS Document-Based Middleware
- OS File System-Based Middleware
- OS Shared Object-Based Middleware
- Operating System Security
- Operating System Security
- OS Threats
- OS Intruders
- OS Accidental Data Loss
- Basics of Cryptography
- Secret-Key Cryptography
- Public-Key Cryptography
- OS Digital Signatures
- OS User Authentication
- OS Trojan Horses
- OS Login Spoofing
- OS Logic Bombs
- OS Trap Doors
- OS Viruses
- OS AntiViruses
- OS Internet Worms
- Give Online Test
- All Test List
- Operating System Test
OS System Calls
Operating system provides the set of system calls that define the interface between the user programs and the operating system.
The system calls available in the interface vary from OS to OS (Operating System to Operating System).
Operating Systems (OSs) have system calls for reading files.
Unix has a read system call with the following three parameters.
- to specify the file
- to tell where the data are to be put
- to tell how many bytes to read
As you know that the actual mechanics of issuing a system call are highly machine dependent and therefore it must be expressed in assembly language code.
A procedure library is provided to make system calls form C programs and also from other languages as well.
Making a system call is a special kind of making a procedure call.
Procedure calls don't enter the kernel whereas system calls do.
System call has the following three parameters.
- specifying the file
- pointing to the buffer
- giving the number of bytes to read
Here is a sample of a system call from C program.
count = read(fd, buffer, nbytes);
The system call return the number of bytes actually read in count.
In case, if the system call can't be carried out, either due to an invalid parameter or a disk error, count is set to -1, and the error number is put in a global variable, errno.
Now, let's take a look at some of the major POSIX system calls. Here the return code s is -1 in case if an error has occurred.
The return code is given as follows.
- pid is process id
- fd is a file descriptor
- n is a byte count
- position is an offset within the files
- seconds is the elapsed time
System Calls for Process Management
(1) Create a child process identical to the parent:
pid = fork()
(2) Wait for a child to terminate:
pid = waitpid(pid, &statloc, options)
(3) Replace a process core image:
s = execve(name, argv, environp)
(4) Terminate the process execution and return status:
exit(status)
System Calls for File Management
(1) Open a file for reading, writing, or for both:
fd = open(file, how, ...)
(2) Close an open file:
s = close(fd)
(3) Read the data from a file into a buffer:
n = read(fd, buffer, nbytes)
(4) Write the data from a buffer into a file:
n = write(fd, buffer, nbytes)
(5) Move the file pointer:
position = lseek(fd, offset, whence)
(6) Get a file's status information:
s = stat(name, &buf)
System Calls for Directory and File System Management
(1) Create a new directory:
s = mkdir(name, mode)
(2) Remove an empty directory:
s = rmdir(name)
(3) Create a new entry, name2, pointing to name1:
s = link(name1, name2)
(4) Remove a directory entry:
s = unlink(name)
(5) Mount a file system:
s = mount(special, name, flag)
(6) Unmount a file system:
s = umount(special)
System Calls for Miscellaneous
(1) Change the working directory:
s = chdir(dirname)
(2) Change a file's protection bits:
s = chmod(name, mode)
(3) Send a signal to a process:
s = kill(pid, signal)
(4) Get the elapsed time since January 1, 1970:
seconds = time(&seconds)
System Calls for Windows Win32 API
So far we have discussed or focused primarily on Unix. Now let's take a look at all the system calls for Windows Win32 API.
Here is a table describes the system calls for Windows Win32 API. Here, the Win32 API calls, roughly correspond to the Unix calls as discussed or given above.
Unix | Win32 | Description |
---|---|---|
fork | CreateProcess | Create a new process |
waitpid | WaitForSingleObject | Can wait for a process to exit |
execve | CreateProcess = fork + execve | |
exit | ExitProcess | Terminate execution |
open | CreateFile | Create a file or open an existing file |
close | CloseHandle | Close a file |
read | ReadFile | Read data from a file |
write | WriteFile | Write data to a file |
lseek | SetFilePointer | Move the file pointer |
stat | GetFileAttributesEx | Get various file attributes |
mkdir | CreateDirectory | Create a new directory |
rmdir | RemoveDirectory | Remove an empty directory |
unlink | DeleteFile | Destroy an existing file |
time | GetLocalTime | Get the current time |
chdir | SetCurrentDirectory | Change the current working directory |
link | Not supported by Win32 | |
mount | Not supported by Win32 | |
umount | Not supported by Win32 | |
chmod | Not supported by Win32 | |
kill | Not supported by Win32 |
« Previous Tutorial Next Tutorial »
Like/Share Us on Facebook 😋