PROGRAM 1
PROGRAM 1
OBJECTIVES
FEATURES OF LINUX
LINUX KERNEL
SYSTEM LIBRARIES
LINUX LICENSING
KERNEL MODULES
1 ls Directory listing
4 ls -s sort by size
7 clear
• 4-read(r)
• 2-write(w)
• 1-execute(x)
OUTPUTS
❖ Command No.1: ls
Directory listing
sort by size
❖ Command No. 5: ls-h
SYSTEM CALLS
a. Process management: fork(), exec(), wait(),
sleep() …
User Mode:
Kernel Mode:
❖ The system starts in kernel mode when it boots and after the
operating system is loaded, it executes applications in user mode.
❖ There are some privileged instructions that can only be executed in
kernel mode. These are interrupt instructions, input output
management etc
❖ Process Control
❖ File Management
❖ Device Management
❖ Information Maintenance
❖ Communications
❖ Process Control Functions:
➢ End and Abort
➢ Load and Execute
➢ Create Process and Terminate Process
➢ Wait and Signed Event
➢ Allocate and free memory
❖ File Management Functions:
➢ Create a file
➢ Delete file
➢ Open and close file
➢ Read, write, and reposition
➢ Get and set file attributes
❖ Device Management Functions:
➢ Request and release device
➢ Logically attach/ detach devices
➢ Get and Set device attributes
❖ Information Maintenance Functions:
➢ Get or set time and date
➢ Get process and device attributes
❖ Communication Functions:
➢ Create, delete communications connections
➢ Send, receive message
➢ Help OS to transfer status information
➢ Attach or detach remote devices
PROCESS CREATION
❖ Open: The open() system call allows you to access a file on a file
system. It allocates resources to the file. Many processes can open a
file at once or by a single process only.
❖ Read:It is used to obtain data from a file on the file system. It
accepts three arguments in general:
➢ A file descriptor.
➢ A buffer to store read data.
➢ The number of bytes to read from the file.
❖ Wait: In some systems, a process may have to wait for another
process to complete its execution before proceeding. When a
parent process makes a child process, the parent process execution
is suspended until the child process is finished. The wait() system
call is used to suspend the parent process. Once the child process
has completed its execution, control is returned to the parent
process.
❖ Write: It is used to write data from a user buffer to a device like a
file. It takes three arguments in general:
➢ A file descriptor.
➢ A pointer to the buffer in which data is saved.
➢ The number of bytes to be written from the buffer.
PROGRAMS
1. Display parent id and process id.
#include<stdio.h>
int main()
OUTPUT:
2. Fork System calls.
#include <stdio.h>
#include <sys/types.h>
int main()
fork();
fork();
fork();
printf("hello\n");
return 0;
OUTPUT:
main()
fork();
OUTPUT:
#include<signal.h>
main()
pid_t pid;
pid=fork();
if(pid==0)
printf("\nparent id%d\n",getppid());
sleep(30);
else
kill(getppid(),SIGKILL);
}
printf("after fork chid finished\n\n");
OUTPUT:
main()
int pid;
pid=fork();
if(pid>0)
printf("from parent\n");
else
printf("from children\n");
OUTPUT:
6. File management system calls
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdio.h>
int main()
int n,fd;
char buff[50];
return 0;
OUTPUT: