This document provides instructions for various exercises to be completed as part of an Operating Systems lab manual. It includes exercises on system calls like fork, exec, wait; I/O system calls; simulating commands like ls and grep; scheduling algorithms like FCFS, SJF, priority, round robin; inter-process communication using shared memory, pipes, message queues; the producer-consumer problem using semaphores; and memory management schemes including paging, segmentation, and file allocation techniques. Example code is provided for implementing different memory management algorithms using concepts like free space list, allocated space list, and block merging.
This program implements the First Come First Serve (FCFS) CPU scheduling algorithm in C. It takes the arrival time and service time of each process as input, calculates the start time, finish time, waiting time and turnaround time of each process, and outputs these values along with the average waiting time and average turnaround time. The processes are scheduled in the order of their arrival, with no preemption, following the FCFS principle.
This Operating System lab manual is designed strictly according to BPUT Syllabus.Any suggestions or comments are well come at neelamani.samal@gmail.com
SGN Introduction to UNIX Command-line 2015 part 1solgenomics
This document provides an introduction to UNIX commands presented at a workshop on March 17, 2015. It covers navigating file systems, wildcards and shortcuts, file permissions, compression and networking commands, text file manipulation, command line pipelines, and an introduction to bash scripts. The document explains that most biological data analysis software uses UNIX command lines, data analysis on servers is faster, and NGS files require command line tools due to their large size.
This document provides an index of 21 coding topics that include performing arithmetic operations, comparison of numbers, compound interest calculation, prime number checking, and palindrome checking. It also includes displaying a Fibonacci series, calculating simple interest, and swapping numbers without using three variables. The index provides the topic name and number for each item.
Slides from the Introduction to UNIX Command-Lines class from the BTI Plant Bioinformatics course 2014. This is a course teach by the Sol Genomics Network researchers at the Boyce Thompson Institute.
The document provides an overview of various Unix/Linux command line concepts across 5 chapters. It describes commands for listing files and directories (ls), creating directories (mkdir), changing directories (cd), viewing the current directory (pwd), copying, moving and removing files (cp, mv, rm), searching files (grep), viewing processes (ps), running jobs in background (&), managing jobs (jobs, fg, bg) and killing processes (kill). It also covers file permissions (chmod), symbolic and hard links (ln), input/output redirection (> ,|), piping (|) and getting help (man, whatis).
This document provides summaries of 30 common Unix commands. It begins with an introduction explaining the purpose and scope of the document. The commands are then listed alphabetically, with each getting a brief 1-2 sentence description. For some commands, simple examples of usage are also provided. The document aims to give beginners a quick overview of the basic usage of important Unix commands.
This program implements the First Come First Serve (FCFS) CPU scheduling algorithm in C. It takes the arrival time and service time of each process as input, calculates the start time, finish time, waiting time and turnaround time of each process, and outputs these values along with the average waiting time and average turnaround time. The processes are scheduled in the order of their arrival, with no preemption, following the FCFS principle.
This Operating System lab manual is designed strictly according to BPUT Syllabus.Any suggestions or comments are well come at neelamani.samal@gmail.com
SGN Introduction to UNIX Command-line 2015 part 1solgenomics
This document provides an introduction to UNIX commands presented at a workshop on March 17, 2015. It covers navigating file systems, wildcards and shortcuts, file permissions, compression and networking commands, text file manipulation, command line pipelines, and an introduction to bash scripts. The document explains that most biological data analysis software uses UNIX command lines, data analysis on servers is faster, and NGS files require command line tools due to their large size.
This document provides an index of 21 coding topics that include performing arithmetic operations, comparison of numbers, compound interest calculation, prime number checking, and palindrome checking. It also includes displaying a Fibonacci series, calculating simple interest, and swapping numbers without using three variables. The index provides the topic name and number for each item.
Slides from the Introduction to UNIX Command-Lines class from the BTI Plant Bioinformatics course 2014. This is a course teach by the Sol Genomics Network researchers at the Boyce Thompson Institute.
The document provides an overview of various Unix/Linux command line concepts across 5 chapters. It describes commands for listing files and directories (ls), creating directories (mkdir), changing directories (cd), viewing the current directory (pwd), copying, moving and removing files (cp, mv, rm), searching files (grep), viewing processes (ps), running jobs in background (&), managing jobs (jobs, fg, bg) and killing processes (kill). It also covers file permissions (chmod), symbolic and hard links (ln), input/output redirection (> ,|), piping (|) and getting help (man, whatis).
This document provides summaries of 30 common Unix commands. It begins with an introduction explaining the purpose and scope of the document. The commands are then listed alphabetically, with each getting a brief 1-2 sentence description. For some commands, simple examples of usage are also provided. The document aims to give beginners a quick overview of the basic usage of important Unix commands.
50 most frequently used unix linux commands (with examples)Rodrigo Maia
This document provides examples for 50 common Linux commands, including tar, grep, find, ssh, sed, awk, vim, diff, sort, and more. It explains practical uses for each command and provides short code snippets to demonstrate basic functionality. The commands cover a wide range of tasks like archiving, searching, editing, comparing, and managing files, processes and system resources.
This document provides information about creating partitions and filesystems in Linux. It discusses various Linux filesystem types like ext2, ext3, xfs, reiserfs v3, and vfat. It covers the commands and tools used to create partitions (fdisk, mkfs), filesystems (mkfs), and swap spaces (mkswap, swapon). It also discusses viewing filesystem information, mounting filesystems, and the Filesystem Hierarchy Standard for directory structure in Linux.
The document provides tips for improving productivity when using the Unix command line. It discusses advantages of the shell like flexibility and chaining commands together. It then gives examples of using shell commands in scripting languages. The majority of the document provides examples of specific Unix commands like grep, find, less and their usage for tasks like file searching, viewing files and directory listings. It concludes with tips on aliases, environment variables and symbolic links.
This document provides an overview of basic Linux commands, including man for accessing manual pages, ls for listing directory contents, mkdir for creating directories, cd for changing directories, pwd for printing the working directory, and ~ for accessing the home directory. It also covers commands for copying, moving, removing files, clearing the screen, viewing file contents, searching within files, counting words, piping commands together, using wildcards, and changing file permissions with chmod. The document encourages learning through manual pages and understanding error messages.
The document provides information on basic Linux commands for working with files, permissions, users and running levels. Some key points:
- Commands like ls, du, df, free are used to view disk usage, files, permissions and available memory. chmod, chown, chgrp change file/folder permissions and ownership.
- Permissions are represented by rwx for read, write and execute for the user, group and others. Numerical values like 755 can set complex permission schemes.
- Linux has 7 run levels from 0-6 for different system states like shutdown, single-user mode, multi-user with networking. Services are started via links in run level directories.
- Common commands
This document provides an overview of Linux commands for redirecting standard input, output, and error streams. Some key points covered include:
- Redirecting input (<), output (> and >>), and pipes (|) to send output as input to another command
- Common redirection operators like tee to send output to both a file and stdout, and xargs to expand input to command line arguments
- Redirecting standard error (2>) independently from standard output using 2>, 2>>, 2>&1
- Using command substitution (`command` and $(command)) to capture output and use as arguments
- Chaining commands together in pipelines (|) to filter and transform text streams
- Examples of
This document provides an overview of basic Unix commands including ls, cd, pwd, mkdir, rm, rmdir, cp, find, touch, echo, cat, who, and du. It explains what each command is used for and provides examples of common usages. The document serves as a beginner's guide to learning Unix commands.
The document provides descriptions of various Linux commands for basic usage and pentesting. It describes commands for making directories (mkdir), deleting empty directories (rmdir), viewing processes (ps), checking username (whoami), checking disk space (df), displaying date and time (date), checking connectivity (ping), downloading files (wget), looking up domain registration records (whois), navigating directories (cd), listing directory contents (ls), displaying command manuals (man), displaying text files (cat), copying files (cp), moving and renaming files (mv), removing files and directories (rm), creating empty files (touch), searching files (grep), using administrative privileges (sudo), viewing start of files (head), viewing end of files (
The document provides summaries of common Linux commands, including their most common uses. Some key commands covered are ls, which lists files and directories; cd, which changes the current working directory; and man, which provides documentation for other commands. The document also discusses commands for viewing system processes and users, like top, w, who, and finger.
The document provides an overview of Linux commands and the command line interface. It discusses:
1. Why the command line interface is useful and how to open the terminal emulator.
2. The different types of shells available in Linux and how to check the current shell or change shells.
3. Common Linux directory structures like /bin and /usr/bin that contain executable programs and commands.
This document provides an overview of common Linux commands used to process text streams and filter output, including cat, cut, head, tail, and split. It discusses how these commands can be used to select, sort, reformat, and summarize data by printing certain parts of files like columns, lines, or characters. Redirection is also covered as a way to modify command input and output. The goal is to explain the key knowledge areas and objectives for the Junior Level Linux Certification exam related to GNU and Unix commands.
101 4.2 maintain the integrity of filesystemsAcácio Oliveira
The document discusses maintaining the integrity of Linux filesystems. It covers using tools like fsck, e2fsck, debugfs, tune2fs, du, and df to check filesystems for errors, monitor free space and inodes, and repair simple filesystem issues. Specific examples are provided on checking filesystems by device path, label, or UUID. It also addresses errors that may occur when checking mounted filesystems and describes using tune2fs to view block counts and filesystem journaling status.
The document provides summaries of common Linux commands, including their most common uses. Some key commands covered are ls, which lists files and directories; cd, which changes the current working directory; and man, which displays manuals for commands. The document also discusses commands for checking network connectivity like ping and ifconfig, managing processes like top and ps, and manipulating files and directories like touch, rm, and chmod.
File is a container for storing information. It can be treated as a sequence of characters. Unlike the old DOS files, a UNIX file doesn‟t contain eof (end- of –file) mark. A file‟s size is not stored in the file, nor even its name. All files attributes are kept in separate area of hard disk, not accessible to humans, but only to the kernel.ThesisScientist.com
This document provides information about various Linux commands. It begins by defining what a command is and explaining the different types of commands - built-in shell commands and external commands. It then discusses command navigation shortcuts and various file manipulation commands like mkdir, rmdir, touch, cp, rm, man, head, tail, cat, tac, more and files. The document also covers the Linux filesystem hierarchy standard and describes the main directories for binaries, configuration, data and memory. Overall, the document serves as a guide to common Linux commands and filesystem structure.
The document provides an overview of common Linux commands, including commands for executing other commands, navigating directories, listing and copying files, managing users and permissions, searching for files, processing text, managing archives, and compressing files. Examples are given for commands like ls, cd, cp, mv, rm, who, echo, alias, awk, chown, diff, grep, pushd, kill, df, cat, tar, gzip, su. Brief descriptions are provided for most commands and references are given at the end for additional Linux resources.
The e-book covers some of the really cool ways on how to go about using Linux from Terminal making your daily work much more efficient, less time consuming and of course geeky.
Useful Linux and Unix commands handbookWave Digitech
This article provides practical examples for most frequently used commands in Linux / UNIX. Helpful for Engineers and trainee engineers, Software developers. A handy notes for all Linux & Unix commands.
This document provides an overview of virtual memory concepts including segmentation, paging, virtual addresses, linear addresses, physical addresses, page tables, and page directories. It also describes initializing memory management structures like pages and page tables during boot up. Finally, it outlines interfaces for key virtual memory functions like walking the page table, inserting/removing pages, and looking up the physical page for a virtual address.
50 most frequently used unix linux commands (with examples)Rodrigo Maia
This document provides examples for 50 common Linux commands, including tar, grep, find, ssh, sed, awk, vim, diff, sort, and more. It explains practical uses for each command and provides short code snippets to demonstrate basic functionality. The commands cover a wide range of tasks like archiving, searching, editing, comparing, and managing files, processes and system resources.
This document provides information about creating partitions and filesystems in Linux. It discusses various Linux filesystem types like ext2, ext3, xfs, reiserfs v3, and vfat. It covers the commands and tools used to create partitions (fdisk, mkfs), filesystems (mkfs), and swap spaces (mkswap, swapon). It also discusses viewing filesystem information, mounting filesystems, and the Filesystem Hierarchy Standard for directory structure in Linux.
The document provides tips for improving productivity when using the Unix command line. It discusses advantages of the shell like flexibility and chaining commands together. It then gives examples of using shell commands in scripting languages. The majority of the document provides examples of specific Unix commands like grep, find, less and their usage for tasks like file searching, viewing files and directory listings. It concludes with tips on aliases, environment variables and symbolic links.
This document provides an overview of basic Linux commands, including man for accessing manual pages, ls for listing directory contents, mkdir for creating directories, cd for changing directories, pwd for printing the working directory, and ~ for accessing the home directory. It also covers commands for copying, moving, removing files, clearing the screen, viewing file contents, searching within files, counting words, piping commands together, using wildcards, and changing file permissions with chmod. The document encourages learning through manual pages and understanding error messages.
The document provides information on basic Linux commands for working with files, permissions, users and running levels. Some key points:
- Commands like ls, du, df, free are used to view disk usage, files, permissions and available memory. chmod, chown, chgrp change file/folder permissions and ownership.
- Permissions are represented by rwx for read, write and execute for the user, group and others. Numerical values like 755 can set complex permission schemes.
- Linux has 7 run levels from 0-6 for different system states like shutdown, single-user mode, multi-user with networking. Services are started via links in run level directories.
- Common commands
This document provides an overview of Linux commands for redirecting standard input, output, and error streams. Some key points covered include:
- Redirecting input (<), output (> and >>), and pipes (|) to send output as input to another command
- Common redirection operators like tee to send output to both a file and stdout, and xargs to expand input to command line arguments
- Redirecting standard error (2>) independently from standard output using 2>, 2>>, 2>&1
- Using command substitution (`command` and $(command)) to capture output and use as arguments
- Chaining commands together in pipelines (|) to filter and transform text streams
- Examples of
This document provides an overview of basic Unix commands including ls, cd, pwd, mkdir, rm, rmdir, cp, find, touch, echo, cat, who, and du. It explains what each command is used for and provides examples of common usages. The document serves as a beginner's guide to learning Unix commands.
The document provides descriptions of various Linux commands for basic usage and pentesting. It describes commands for making directories (mkdir), deleting empty directories (rmdir), viewing processes (ps), checking username (whoami), checking disk space (df), displaying date and time (date), checking connectivity (ping), downloading files (wget), looking up domain registration records (whois), navigating directories (cd), listing directory contents (ls), displaying command manuals (man), displaying text files (cat), copying files (cp), moving and renaming files (mv), removing files and directories (rm), creating empty files (touch), searching files (grep), using administrative privileges (sudo), viewing start of files (head), viewing end of files (
The document provides summaries of common Linux commands, including their most common uses. Some key commands covered are ls, which lists files and directories; cd, which changes the current working directory; and man, which provides documentation for other commands. The document also discusses commands for viewing system processes and users, like top, w, who, and finger.
The document provides an overview of Linux commands and the command line interface. It discusses:
1. Why the command line interface is useful and how to open the terminal emulator.
2. The different types of shells available in Linux and how to check the current shell or change shells.
3. Common Linux directory structures like /bin and /usr/bin that contain executable programs and commands.
This document provides an overview of common Linux commands used to process text streams and filter output, including cat, cut, head, tail, and split. It discusses how these commands can be used to select, sort, reformat, and summarize data by printing certain parts of files like columns, lines, or characters. Redirection is also covered as a way to modify command input and output. The goal is to explain the key knowledge areas and objectives for the Junior Level Linux Certification exam related to GNU and Unix commands.
101 4.2 maintain the integrity of filesystemsAcácio Oliveira
The document discusses maintaining the integrity of Linux filesystems. It covers using tools like fsck, e2fsck, debugfs, tune2fs, du, and df to check filesystems for errors, monitor free space and inodes, and repair simple filesystem issues. Specific examples are provided on checking filesystems by device path, label, or UUID. It also addresses errors that may occur when checking mounted filesystems and describes using tune2fs to view block counts and filesystem journaling status.
The document provides summaries of common Linux commands, including their most common uses. Some key commands covered are ls, which lists files and directories; cd, which changes the current working directory; and man, which displays manuals for commands. The document also discusses commands for checking network connectivity like ping and ifconfig, managing processes like top and ps, and manipulating files and directories like touch, rm, and chmod.
File is a container for storing information. It can be treated as a sequence of characters. Unlike the old DOS files, a UNIX file doesn‟t contain eof (end- of –file) mark. A file‟s size is not stored in the file, nor even its name. All files attributes are kept in separate area of hard disk, not accessible to humans, but only to the kernel.ThesisScientist.com
This document provides information about various Linux commands. It begins by defining what a command is and explaining the different types of commands - built-in shell commands and external commands. It then discusses command navigation shortcuts and various file manipulation commands like mkdir, rmdir, touch, cp, rm, man, head, tail, cat, tac, more and files. The document also covers the Linux filesystem hierarchy standard and describes the main directories for binaries, configuration, data and memory. Overall, the document serves as a guide to common Linux commands and filesystem structure.
The document provides an overview of common Linux commands, including commands for executing other commands, navigating directories, listing and copying files, managing users and permissions, searching for files, processing text, managing archives, and compressing files. Examples are given for commands like ls, cd, cp, mv, rm, who, echo, alias, awk, chown, diff, grep, pushd, kill, df, cat, tar, gzip, su. Brief descriptions are provided for most commands and references are given at the end for additional Linux resources.
The e-book covers some of the really cool ways on how to go about using Linux from Terminal making your daily work much more efficient, less time consuming and of course geeky.
Useful Linux and Unix commands handbookWave Digitech
This article provides practical examples for most frequently used commands in Linux / UNIX. Helpful for Engineers and trainee engineers, Software developers. A handy notes for all Linux & Unix commands.
This document provides an overview of virtual memory concepts including segmentation, paging, virtual addresses, linear addresses, physical addresses, page tables, and page directories. It also describes initializing memory management structures like pages and page tables during boot up. Finally, it outlines interfaces for key virtual memory functions like walking the page table, inserting/removing pages, and looking up the physical page for a virtual address.
GUN Make is a tool used to automate the building of executables from source code. It determines which files need to be recompiled based on timestamps and builds the necessary targets. Rules define dependencies and commands to transform files. Variables, macros, conditionals, and functions allow for complex logic and reuse in the makefile. Includes allow splitting makefiles into modular pieces.
The document describes four different CPU scheduling algorithms: First Come First Serve (FCFS), Shortest Job First (preemptive and non-preemptive), Priority scheduling (non-preemptive), and Round Robin. For each algorithm, pseudocode is provided to simulate the scheduling of processes and calculate metrics like waiting time and turnaround time. The FCFS algorithm calculates these metrics in a straightforward manner based on arrival time and burst time of each process. Shortest Job First simulates sorting processes by burst time and calculating wait times and turnaround times accordingly. Priority scheduling first sorts by priority then calculates metrics. Round Robin simulates time slicing by allocating a time quantum to each process in turn.
Human:
This document provides information about an OS lab manual, including definitions of operating systems, computer system components, Windows 2000 architecture and components, and other topics like LDAP, DNS, and Active Directory. Specifically, it defines operating systems, their goals, and components. It describes the Windows 2000 architecture in layers and subsystems. It also explains the Windows 2000 kernel, executive, and subsystems like object manager, virtual memory manager, and process manager.
This document contains programs and algorithms for simulating different CPU scheduling algorithms like FCFS, SJF, Priority and Round Robin. It also contains a program for implementing the Producer-Consumer problem using semaphores and an algorithm for implementing optimal page replacement.
Operating System Tutoring #1.
by Aerosystem Software Lab. @ Korea Aerospace Univ.
This is tutoring slide for the students who were not understood well about operating system or fundamentals of computer engineering. This slide may has some misconceptions or inappropriate examples. Any feedback is welcomed.
운영체제 튜터링 #1.
- 항공 소프트웨어 연구실 @ 한국항공대학교
본 슬라이드는 튜터링 강의자료로, 운영체제에 대한 개념이나 컴퓨터공학 기초지식이 부족한 학생들을 기준으로 작성하였습니다. 본 슬라이드에 일부 잘못된 개념이나 부적절한 예시가 포함되어 있을 수도 있습니다. 피드백 환영합니다.
This document contains 8 C programming code examples demonstrating various scheduling algorithms:
1. First Come First Serve scheduling
2. Non-preemptive Shortest Job First scheduling
3. Round Robin scheduling
4. Priority scheduling
5. Banker's algorithm for deadlock avoidance
6. Producer-consumer problem synchronization
7. Dekker's algorithm for mutual exclusion
Each program example includes comments explaining the algorithm and includes functions to calculate waiting times, turnaround times, and other metrics.
This document contains the code for simulating different CPU scheduling algorithms including FCFS, SJF, and priority scheduling. It includes the code to input process details like name, arrival time, and burst time. It then calculates start time, waiting time, turnaround time, and response time for each process. The average waiting time and average turnaround time are also calculated at the end for each algorithm.
This document outlines the workflow process and structure for encoding video and audio files using FFmpeg. It provides a 10 step standard operating procedure (SOP) for encoding files that includes: 1) including headers, 2) linking libraries, 3) setting up output format, 4) preparing codec structures, 5) setting up video codec, 6) setting up audio codec, 7) opening file descriptor and writing header, 8) writing data packets, 9) closing file descriptor, and 10) calculating presentation timestamp (PTS) values.
The document provides an overview of SSL and OpenSSL. It discusses generating keys and certificates, setting up SSL contexts, creating secure connections, reading/writing data, and handling errors. It also provides code snippets for an echo client and server. The echo server loads a certificate, sets up a listening BIO, accepts connections, and performs handshakes. The handshake process involves a client sending a "hello" message and the server responding with its own parameters to establish encryption.
The document describes designing an online course reservation system using Rational Rose software. The system would allow students to register for courses, view course catalogs, and professors to sign up to teach courses and record grades. It would have four modules: student login, student registration, course registration, and course inquiry. The system was implemented using Visual Basic 6.0, with Access as the backend database. UML diagrams like use case, class, sequence, and deployment diagrams were created to model and design the system. The project was carried out sequentially and resulted in an efficient online course reservation system.
The document summarizes the phases of the software development life cycle (SDLC) and provides details about system requirement specification for an army management system project. It describes the typical phases in SDLC models such as waterfall, spiral, agile etc. It then covers the specific phases in more detail - preliminary analysis, system analysis, design, development, integration and testing, acceptance and deployment, maintenance. Lastly, it discusses system requirement specification, including UML notations, diagrams to be used and provides a brief overview of class diagrams.
This document provides an overview of IPv6 functionality and describes how to build an IPv6 environment. It outlines IPv6 addressing formats including unicast, multicast, anycast, and global unicast addresses. It also explains stateless and stateful autoconfiguration methods for IPv6 hosts to obtain addresses and configure themselves on the network. The document concludes by describing how to set up routers and hosts in IPv6 networks on Linux systems.
The document is a slide presentation on UML modeling and profiling from a software engineering course. It introduces UML and the concepts of metamodeling. It explains that UML is used to specify, visualize, construct and document software system artifacts. The presentation then outlines the typical steps in UML modeling: 1) modeling use cases, 2) modeling system structure with classes and components, and 3) modeling deployment to hardware nodes.
This document provides an overview and instructions for basic commands and operations in the UNIX operating system. It discusses the kernel and shell structure of UNIX, the file hierarchy, and common commands for file manipulation, processing, and navigation. It also provides a tutorial on the vi text editor, including instructions for basic cursor movement, text insertion, changing, and deletion.
The document provides an overview of the Unified Modeling Language (UML) including its key concepts, terms, and diagram types. It discusses object-orientation, use cases, class diagrams, behavioral modeling using sequence, collaboration, state chart and activity diagrams. It also covers implementation using component and deployment diagrams. The main UML diagram types are use case, class, sequence, state chart, activity, component and deployment diagrams.
The document discusses memory reference instructions in a processor. It explains that bits 12-14 in the instruction register determine the memory reference instruction type, which can be AND to AC, ADD to AC, LDA, STA, BUN, BSA, or ISZ. It then describes the operation of each instruction type, including which decoder line is activated and the timing signals used to access memory and update registers.
MATLAB programs Power System Simulation lab (Electrical Engineer)Mathankumar S
The document contains MATLAB code for calculating line constants (inductance L and capacitance C) for overhead transmission lines with different configurations (single-circuit, single-circuit with multiple subconductors, and double-circuit). It requests user input of various line parameters and geometric mean distances and then calculates L and C values. Additional code calculates the network bus admittance matrix and transmission line losses.
This document provides instructions for commands in Linux including commands to display the date and time, calendar, echo text, view who is logged in, change directories, manage files and directories, and more. It explains the syntax and use of commands like date, cal, echo, who, cd, ls, mkdir, rmdir, cat, cp, mv, rm, sort, and man. The objective is to study and execute basic commands in the Linux operating system.
This document provides an overview of the basics of Unix including its history and development. It describes Unix as a command user interface (CUI) operating system that is case sensitive and allows multitasking. Various flavors of Unix are then listed along with common commands like date, cal, uname and their usage. The document also covers working with files and directories through commands like cat, touch, rm, mkdir and managing files through commands like cp, mv and viewing files with ls.
The document provides an overview of basic Linux commands organized into the following sections:
1. General purpose utilities such as date, echo, printf, calculator applications
2. Linux file system structure and commands for viewing file attributes, permissions, ownership
3. Commands for file handling, concatenation, pagination and comparing files
The document provides an overview of basic Linux commands organized into the following sections:
1. General purpose utilities such as date, echo, printf, calculator commands etc.
2. Linux file system structure and commands for viewing file attributes, permissions and ownership.
3. Commands for file handling, concatenating, comparing, viewing and getting statistics of files.
This document provides an introduction and overview of shell scripting in Linux. It discusses what a shell script is, when they should and should not be used, examples of common shell scripts, and an introduction to programming features commonly used in shell scripts such as variables, conditionals, loops, command line arguments, and more. Key points covered include that shell scripts allow automating command execution, are useful for repetitive tasks, and come with programming features to customize behavior.
The document summarizes the usage of various Linux commands like cd, bc, man, who, whoami, pwd, mkdir, rmdir, ls, touch, mv, date, cat, more, less, print, echo, lp, rm, cp and their options. It provides the syntax and examples of using each command. The commands covered are for directory navigation, file manipulation, text processing and printing files in Linux operating system.
This document provides 50 examples of common Linux/Unix commands organized by command name. It begins with tar, grep, find, ssh, sed, awk, vim, diff, sort, and export examples. The document is intended as a quick reference for users to learn practical uses of fundamental Linux commands.
The document provides information about the LAMP stack and its components - Linux, Apache, MySQL, and PHP. It then discusses Linux commands, directories, editors, and scheduling tasks using cron jobs. Key points are:
- LAMP is an open source software solution stack using Linux, Apache, MySQL, and PHP.
- Linux commands allow users to navigate files/folders, view processes, manage users, and more.
- Linux directories include /, /boot, /bin, /lib, /usr for storing system and user files and apps.
- Cron jobs allow scheduling commands to run periodically using a crontab file.
An operating system acts as an interface between hardware and software, managing resources and presenting an easier programming interface than the underlying hardware. The UNIX system is organized into three levels - the kernel which manages tasks and storage, the shell which connects programs and executes commands, and tools/applications which provide additional functionality. PuTTY is a free and open-source terminal emulator and SSH client most commonly used to access UNIX/Linux systems remotely from Windows. The course objectives are to learn UNIX commands, shell programming, process management, memory management, file organization, and implementing related algorithms.
5_File_Handling_Commands__vi_editor_and_environment_variablesGautam Raja
This document provides a content manual for the TATA CONSULTANCY SERVICES Pre ILP – Unix LOUNGE. It contains two chapters, the first discussing basic Unix file commands like touch, cat, cp, mv, rm, and find. The second chapter covers basics of the vi text editor and environment variables. It describes vi modes, commands for navigation, editing, saving and exiting. It also explains how environment variables control the system behavior and lists some common ones like HOME, PATH, and PS1.
This document provides an overview of system administrator tasks and basic UNIX concepts. It discusses the roles and responsibilities of system administrators, the structure and components of UNIX operating systems, basic commands for navigating the file system, managing files and directories, editing text, and running processes. It also covers shells, variables, and cron jobs for scheduling automated tasks. The document concludes with introductions to AIX operating systems and IBM pSeries servers.
AARAV NAYAN OPERATING SYSTEM LABORATORY PCAAaravNayan
This document contains an operating system lab file that lists 12 Unix commands: telnet, ls, echo, cd, pwd, mkdir, cp, rm, rmdir, mv, cat, and sort. For each command, it provides the syntax, a brief description, and examples of use. It also lists the date command and provides examples of using it to display times in different formats, set the system date, and display past and future dates.
This document provides instructions for 27 common Linux commands: mkdir, rmdir, ls, cd, cat, touch, wc, who, pwd, rm, mv, chmod, cp, grep, cal, date, vi, tput, ps, export, type, tail, sudo, head, man, clear, and adduser. For each command, it lists the syntax and provides 1-3 examples of common uses. The document is presented over 28 pages with the commands organized topic-by-topic and includes formatting like headings and indentation to aid readability.
This document provides 50 examples of common Linux/Unix commands along with brief explanations and usage examples for each command. Some of the commands highlighted include tar, grep, find, ssh, sed, awk, vim, diff, sort, and ls. The examples cover a wide range of tasks from compressing/extracting files to searching/editing text to managing processes and permissions.
This document provides 50 examples of common Linux/Unix commands along with brief explanations and usage examples for each command. Some of the commands highlighted include tar, grep, find, ssh, sed, awk, vim, diff, sort, export, xargs, ls, pwd, cd, gzip, bzip2, unzip, shutdown, ftp, crontab, service, ps, top, df, kill, rm, cp, mv, cat, mount, chmod, chown, passwd, mkdir, ifconfig, and uname. The document is intended to give readers a quick start on frequently used commands.
The document provides information about the LAMP stack and its components - Linux, Apache, MySQL, and PHP. It then discusses Linux commands, directories, editors, and scheduling tasks using cron jobs. Key points include:
- LAMP is an open source software solution stack using Linux, Apache, MySQL, and PHP. It allows for easy coding and deployment of PHP applications.
- Linux commands covered include cd, ls, pwd, touch, rm. Directories include /, /boot, /bin, /usr, /var. Editors discussed are vi and emacs.
- Cron jobs allow scheduling commands to run on a set schedule using crontab files. Syntax includes minutes, hours, day of month, month
The document provides information about the LAMP stack and its components - Linux, Apache, MySQL, and PHP. It then discusses Linux commands, directories, editors, and scheduling tasks using cron jobs. Key details include that LAMP is an open source software stack using these components, Linux commands allow managing files and systems, directories structure the Linux filesystem, vi and cron are tools for text editing and automated tasks.
1. The document provides examples of common Linux commands and their usage including tar, grep, find, ssh, sed, awk, vim, diff, sort, export, xargs, ls, ifconfig, uname, ps, free, top, df, kill, rm, cp, mv, cat, mount, chmod, chown, passwd, mkdir, ifconfig, uname, whereis, whatis, and locate.
2. Examples shown include how to create, extract, and view tar archives, search files with grep, find files, login remotely with ssh, edit files with vim, compare files with diff, view processes with ps, check storage usage with df, terminate processes with kill, manage files
This document provides an introduction to shell programming in Linux. It defines key terms like the kernel, processes, pipes, and filters. It explains that the kernel manages resources and I/O, while processes carry out tasks. Pipes send output between programs and filters perform operations on input. Common shells like Bash, CSH, and KSH are outlined. Shells accept commands and translate them to binary for the OS. Basic Linux commands are listed along with examples. Variables, both system and user-defined, are explained as a way to store and process data in the shell. The document provides steps for writing, naming, running and debugging shell scripts using commands like echo, cat, chmod and expressions. Local and global variables
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
हिंदी वर्णमाला पीपीटी, hindi alphabet PPT presentation, hindi varnamala PPT, Hindi Varnamala pdf, हिंदी स्वर, हिंदी व्यंजन, sikhiye hindi varnmala, dr. mulla adam ali, hindi language and literature, hindi alphabet with drawing, hindi alphabet pdf, hindi varnamala for childrens, hindi language, hindi varnamala practice for kids, https://www.drmullaadamali.com
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
How to Fix the Import Error in the Odoo 17Celine George
An import error occurs when a program fails to import a module or library, disrupting its execution. In languages like Python, this issue arises when the specified module cannot be found or accessed, hindering the program's functionality. Resolving import errors is crucial for maintaining smooth software operation and uninterrupted development processes.
1. Operating System Lab Manual
Page 1
OPERATING SYSTEMS LAB
(Implement the following on LINUX or other Unix like platform. Use C for high level
language implementation)
1. Write programs using the following system calls of UNIX operating system: fork, exec,
getpid, exit, wait, close, stat, opendir, readdir
2. Write programs using the I/O system calls of UNIX operating system (open, read,
write, etc)
3. Write C programs to simulate UNIX commands like ls, grep, etc.
4. Given the list of processes, their CPU burst times and arrival times, display/print the Gantt
chart for FCFS and SJF. For each of the scheduling policies, compute and print the average
waiting time and average turnaround time. (2 sessions)
5. Given the list of processes, their CPU burst times and arrival times, display/print the Gantt
chart for Priority and Round robin. For each of the scheduling policies,compute and print
the average waiting time and average turnaround time. (2sessions)
6. Developing Application using Inter Process communication (using shared memory, pipes
or message queues)
7. Implement the Producer – Consumer problem using semaphores (using UNIX system
calls).
8. Implement some memory management schemes – I
9. Implement some memory management schemes – II
10. Implement any file allocation technique (Linked, Indexed or Contiguous)
Example for exercises 8 & 9 :
Free space is maintained as a linked list of nodes with each node having the starting byte address
and the ending byte address of a free block. Each memory request consists of the process-id and
the amount of storage space required in bytes. Allocated memory space is again maintained as a
linked list of nodes with each node having the process-id, starting byte address and the ending
byte address of the allocated space. When a process finishes (taken as input) the appropriate node
from the allocated list should be deleted and this free disk space should be added to the free space
list. [Care should be taken to merge contiguous free blocks into one single block. This results in
deleting more than one node from the free space list and changing the start and end address in
the appropriate node]. For allocation use first fit, worst fit and best fit
2. Operating System Lab Manual
Page 2
INDEX
E.No Date Contents
1 Shell Programming:
a) Unix Commands
b) Vi Commands
c) Unix Shell programming commands
a) Concatenation of two strings
b) Comparison of two strings
c) Maximum of three numbers
d) Fibonacci series
e) Arithmetic operation using case
2 System Calls
a) Process Creation
b) Executing a command
c) Sleep command
d) Sleep command using getpid
e) Signal handling using kill
k) Wait command
3 I/O System Calls
a) Reading from a file
b) Writing into a file
c) File Creation
4 a)Implementation of ls command
b)Implementation of grep command
5 Given the list of processes, their CPU burst times and arrival times, display/print the Gantt chart for
FCFS and SJF.Print avg.waiting time and turnaround time.
6 Given the list of processes, their CPU burst times and arrival times, display/print the Gantt chart for
Priority and Round robin. Print avg.waiting time and turnaround time.
7 Developing Application using Inter Process communication (using shared memory, pipes or
message queues)
8 Producer-Consumer Problem using Semaphore
9 Memory management Scheme-I
a) Paging Concept
3. Operating System Lab Manual
Page 3
10 Memory management Scheme-II a) Segmentation Concept
11 Implement any file allocation technique (Linked, Indexed or Contiguous)
4. Operating System Lab Manual
Page 4
Ex.No : 1.a UNIX COMMANDS
Date:
AIM :
To study and excute the commands in unix.
COMMAND :
1.Date Command :
This command is used to display the current data and time.
Syntax :
$date
$date +%ch
Options : -
a = Abbrevated weekday.
A= Full weekday.
b = Abbrevated month.
B= Full month.
c = Current day and time.
C= Display the century as a
decimal number
d = Day of the month.
D= Day in „mm/dd/yy‟ format
h = Abbrevated month day.
H = Display the hour.
L = Day of the year.
m = Month of the year.
M = Minute.
P = Display AM or PM
S = Seconds
T = HH:MM:SS format
u = Week of the year.
y = Display the year in 2 digit.
Y = Display the full year.
Z = Time zone .
To change the format :
Syntax : $date „+%H-%M-%S‟
2.Calender Command :
5. Operating System Lab Manual
Page 5
This command is used to display the calendar of the year or the particular month of calendar
year.
Syntax :
a.$cal <year>
b.$cal <month> <year>
Here the first syntax gives the entire calendar for given year & the second Syntax gives the
calendar of reserved month of that year.
3.Echo Command :
This command is used to print the arguments on the screen .
Syntax : $echo <text>
Multi line echo command :
To have the output in the same line , the following commands can be used.
Syntax : $echo <text>text
To have the output in different line, the following command can be used.
Syntax : $echo “text
>line2
>line3”
4.Banner Command :
It is used to display the arguments in „#‟ symbol .
Syntax : $banner <arguments>
5.’who’ Command :
It is used to display who are the users connected to our computer currently.
Syntax : $who – option‟s
Options : -
H–Display the output with headers.
b–Display the last booting date or time or when the system was lastely rebooted.
6.’who am i’ Command :
Display the details of the current working directory.
Syntax : $who am i
7.’tty’ Command :
It will display the terminal name.
Syntax : $tty
8.’Binary’ Calculator Command :
6. Operating System Lab Manual
Page 6
It will change the „$‟ mode and in the new mode, arithematic operations such as
+,,*,/,%,n,sqrt(),length(),=, etc can be performed . This command is used to go to the binary
calculus mode.
Syntax :
$bc operations
^d
$
1 base –inputbase
0 base – outputbase are used for base conversions.
Base :
Decimal = 1 Binary = 2 Octal = 8 Hexa = 16
9.’CLEAR’ Command :
It is used to clear the screen.
Syntax : $clear
10.’MAN’ Command :
It help us to know about the particular command and its options & working. It is like
“help‟ command in windows .
Syntax : $man <command name>
11.MANIPULATION Command :
It is used to manipulate the screen.
Syntax : $tput <argument>
Arguments :
1.Clear – to clear the screen.
2.Longname – Display the complete name of the terminal.
3.SMSO – background become white and foreground become black color.
4.rmso – background become black and foreground becomes white color.
5.Cop R C – Move to the cursor position to the specified location.
6.Cols – Display the number of columns in our terminals.
12.LIST Command :
It is used to list all the contents in the current working directory.
Syntax : $ ls – options <arguments>
If the command does not contain any argument means it is working in the
Current directory.
Options :
a– used to list all the files including the hidden files.
c– list all the files columnwise.
d- list all the directories.
7. Operating System Lab Manual
Page 7
m- list the files separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x-list in column wise sorted order.
DIRECTORY RELATED COMMANDS :
1.Present Working Directory Command :
To print the complete path of the current working directory.
Syntax : $pwd
2.MKDIR Command :
To create or make a new directory in a current directory .
Syntax : $mkdir <directory name>
3.CD Command :
To change or move the directory to the mentioned directory .
Syntax : $cd <directory name.
4.RMDIR Command :
To remove a directory in the current directory & not the current directory itself.
Syntax : $rmdir <directory name>
FILE RELATED COMMANDS :
1.CREATE A FILE :
To create a new file in the current directory we use CAT command. Syntax
:
$cat > <filename.
The > symbol is redirectory we use cat command.
2.DISPLAY A FILE :
To display the content of file mentioned we use CAT command without „>‟ operator.
Syntax :
$cat <filename.
Options –s = to neglect the warning /error message.
3.COPYING CONTENTS :
To copy the content of one file with another. If file doesnot exist, a new file is created
and if the file exists with some data then it is overwritten.
Syntax :
$ cat <filename source> >> <destination filename>
$ cat <source filename> >> <destination filename> it is avoid overwriting.
8. Operating System Lab Manual
Page 8
Options : -
-n content of file with numbers included with blank lines.
Syntax :
$cat –n <filename>
4.SORTING A FILE :
To sort the contents in alphabetical order in reverse order.
Syntax :
$sort <filename >
Option : $ sort –r <filename>
5.COPYING CONTENTS FROM ONE FILE TO ANOTHER :
To copy the contents from source to destination file . so that both contents are same.
Syntax :
$cp <source filename> <destination filename>
$cp <source filename path > <destination filename path>
6.MOVE Command :
To completely move the contents from source file to destination file and to remove the source
file.
Syntax :
$ mv <source filename> <destination filename>
7.REMOVE Command :
To permanently remove the file we use this command .
Syntax :
$rm <filename>
8.WORD Command :
To list the content count of no of lines , words, characters .
Syntax :
$wc<filename>
Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.
9.LINE PRINTER :
9. Operating System Lab Manual
Page 9
To print the line through the printer, we use lp command.
Syntax :
$lp <filename>
10.PAGE Command :
This command is used to display the contents of the file page wise & next page can be viewed
by pressing the enter key.
Syntax :
$pg <filename>
11. FILTERS AND PIPES
HEAD : It is used to display the top ten lines of file.
Syntax: $head<filename>
TAIL : This command is used to display the last ten lines of file.
Syntax: $tail<filename>
PAGE : This command shows the page by page a screenfull of information is displayed after
which the page command displays a prompt and passes for the user to strike the enter key to
continue scrolling.
Syntax: $ls –ap
MORE : It also displays the file page by page .To continue scrolling with more command ,
press the space bar key.
Syntax: $more<filename>
GREP :This command is used to search and print the specified patterns from the file.
Syntax: $grep [option] pattern <filename>
SORT : This command is used to sort the datas in some order.
Syntax: $sort<filename>
PIPE : It is a mechanism by which the output of one command can be channeled into the input
of another command.
Syntax: $who | wc-l
TR :The tr filter is used to translate one set of characters from the standard inputs to another.
Syntax: $tr “[a-z]” “[A-Z]”
10. Operating System Lab Manual
Page 10
COMMUNICATION THROUGH UNIX COMMANDS
MESG
Description: The message command is used to give permission to other users to send
message to your terminal.
Syntax: $mesg y
2.Command: WRITE
Description: This command is used to communicate with other users, who are logged in at
the same time.
Syntax: $write <user name>
3.Command: WALL
Description: This command sends message to all users those who are logged in using
the unix server.
Syntax: $wall <message>
4.Command: MAIL
Description: It refers to textual information, that can be transferred from one user to
another
Syntax: $mail <user name>
5.Command: REPLY
Description: It is used to send reply to specified user.
Syntax: $reply<user name>
RESULT:
EX.NO :1.b vi EDITOR COMMANDS
DATE :
AIM :
To study the various commands operated in vi editor in UNIX.
DESCRIPTION :
The Vi editor is a visual editor used to create and edit text, files, documents and programs. It
displays the content of files on the screen and allows a user to add, delete or change part of text
. There are three modes available in the Vi editor , they are
11. Operating System Lab Manual
Page 11
1.Command mode
2.Input (or) insert mode.
Starting Vi :
The Vi editor is invoked by giving the following commands in UNIX prompt.
Syntax : $vi <filename> (or)
$vi
This command would open a display screen with 25 lines and with tilt (~) symbol at the start of
each line. The first syntax would save the file in the filename mentioned and for the next the
filename must be mentioned at the end.
Options :
1.vi +n <filename> - this would point at the nth line (cursor pos).
2.vi –n <filename> - This command is to make the file to read only to change
from one mode to another press escape key.
INSERTING AND REPLACING COMMANDS :
To move editor from command node to edit mode, you have to press the <ESC> key. For
inserting and replacing the following commands are used.
1.ESC a Command :
This command is used to move the edit mode and start to append after the current character.
Syntax : <ESC> a
2.ESC A COMMAND :
This command is also used to append the file , but this command append at the end of current
line.
Syntax : <ESC> A
3.ESC i Command :
This command is used to insert the text before the current cursor position.
Syntax : <ESC> i
4.ESC I Command :
This command is used to insert at the beginning of the current line.
Syntax : <ESC> I
12. Operating System Lab Manual
Page 12
5.ESC o Command :
This command is insert a blank line below the current line & allow insertion of
contents.
Syntax : <ESC> o
6.ESC O Command :
This command is used to insert a blank line above & allow insertion of contents.
Syntax : <ESC> O
7.ESC r Command :
This command is to replace the particular character with the given characters.
Syntax : <ESC> rx Where x is the new character.
8.ESC R Command :
This command is used to replace the particular text with a given text. Syntax
: <ESC> R text
9.<ESC> s Command :
This command replaces a single character with a group of character .
Syntax : <ESC> s
10.<ESC> S Command :
This command is used to replace a current line with group of characters.
Syntax : <ESC> S
CURSOR MOVEMENT IN vi :
1.<ESC> h :
This command is used to move to the previous character typed. It is used to move to left of the
text . It can also used to move character by character (or) a number of characters. Syntax :
<ESC> h – to move one character to left.
<ESC> nh – tomove „n‟ character to left.
2.<ESC> l :
This command is used to move to the right of the cursor (ie) to the next character. It can
also be used to move the cursor for a number of character.
Syntax : <ESC> l – single character to right.
<ESC> nl - „n‟ characters to right.
3.<ESC> j :
This command is used to move down a single line or a number of lines.
13. Operating System Lab Manual
Page 13
Syntax :
<ESC> j – single down movement.
<ESC> nj – „n‟ times down movement.
4.<ESC> k :
This command is used to move up a single line or a number of lines.
Syntax :
<ESC> k – single line above.
<ESC> nk – „n‟ lines above.
5.ENTER (OR) N ENTER :
This command will move the cursor to the starting of next lines or a group of lines mentioned.
Syntax :
<ESC> enter <ESC> n enter.
6.<ESC> + Command :
This command is used to move to the beginning of the next line.
Syntax :
<ESC> + <ESC> n+
7.<ESC> - Command :
This command is used to move to the beginning of the previous line.
Syntax :
<ESC> - <ESC> n-
8.<ESC> 0 :
This command will bring the cursor to the beginning of the same current line.
Syntax :
<ESC> 0
9.<ESC> $ :
This command will bring the cursor to the end of the current line.
Syntax :
<ESC> $
10.<ESC> ^ :
This command is used to move to first character of first lines.
Syntax :
<ESC> ^
11.<ESC> b Command :
This command is used to move back to the previous word (or) a number of words.
14. Operating System Lab Manual
Page 14
Syntax :
<ESC> b <ESC>nb
12.<ESC> e Command :
This command is used to move towards and replace the cursor at last character of the word
(or) no of words.
Syntax :
<ESC> e <ESC>ne
13.<ESC> w Command :
This command is used to move forward by a single word or a group of words.
Syntax :
<ESC> w <ESC> nw
DELETING THE TEXT FROM Vi :
1.<ESC> x Command :
To delete a character to right of current cursor positions , this command is used.
Syntax :
<ESC> x <ESC> nx
2.<ESC> X Command :
To delete a character to left of current cursor positions , this command is used.
Syntax :
<ESC> X <ESC> nX
3.<ESC> dw Command :
This command is to delete a single word or number of words to right of current cursor
position.
Syntax :
<ESC> dw <ESC> ndw
4.db Command :
This command is to delete a single word to the left of the current cursor position.
Syntax :
<ESC> db <ESC> ndb
5.<ESC> dd Command :
This command is used to delete the current line (or) a number of line below the current
line.
Syntax :
<ESC> dd <ESC> ndd
15. Operating System Lab Manual
Page 15
6.<ESC> d$ Command :
This command is used to delete the text from current cursor position to last character of
current line.
Syntax : <ESC> d$
SAVING AND QUITING FROM vi :- 1.<ESC>
w Command :
To save the given text present in the file.
Syntax : <ESC> : w
2.<ESC> q! Command :
To quit the given text without saving.
Syntax : <ESC> :q!
3.<ESC> wq Command :
This command quits the vi editor after saving the text in the mentioned file.
Syntax : <ESC> :wq
4.<ESC> x Command :
This command is same as „wq‟ command it saves and quit.
Syntax : <ESC> :x
5.<ESC> q Command :
This command would quit the window but it would ask for again to save the file.
Syntax : <ESC> : q
RESULT:
16. Operating System Lab Manual
Page 16
EX.NO :1.c UNIX SHELL PROGRAMMING COMMANDS.
DATE :
AIM :
To study about the Unix Shell Programming Commands.
INTRODUCTION :
Shell programming is a group of commands grouped together under single filename.
After logging onto the system a prompt for input appears which is generated by a Command
String Interpreter program called the shell. The shell interprets the input, takes appropriate
action, and finally prompts for more input. The shell can be used either interactively - enter
commands at the command prompt, or as an interpreter to execute a shell script. Shell scripts
are dynamically interpreted, NOT compiled.
Common Shells.
C-Shell - csh : The default on teaching systems Good for interactive systems Inferior
programmable features
Bourne Shell - bsh or sh - also restricted shell - bsh : Sophisticated pattern matching
and file name substitution
Korn Shell : Backwards compatible with Bourne Shell Regular expression substitution
emacs editing mode
Thomas C-Shell - tcsh : Based on C-Shell Additional ability to use emacs to edit the
command line Word completion & spelling correction Identifying your
shell.
01. SHELL KEYWORDS :
echo, read, if fi, else, case, esac, for , while , do , done, until , set, unset, readonly, shift,
export, break, continue, exit, return, trap , wait, eval ,exec, ulimit , umask.
02. General things SHELL
The shbang line The "shbang" line is the very first line of the script and lets the kernel know what shell
will be interpreting the lines in the script. The shbang line consists of a #! followed
by the full pathname to the shell, and can be followed by options to control the
behavior of the shell.
EXAMPLE
#!/bin/sh
17. Operating System Lab Manual
Page 17
Comments Comments are descriptive material preceded by a # sign. They are in effect until
the end of a line and can be started anywhere on the line.
EXAMPLE
# this text is not
# interpreted by the shell
Wildcards There are some characters that are evaluated by the shell in a special way. They are
called shell metacharacters or "wildcards." These characters are neither numbers
nor letters. For example, the *, ?, and [ ] are used for filename expansion. The <, >,
2>, >>, and | symbols are used for standard I/O redirection and pipes. To prevent
these characters from being interpreted by the shell they must be quoted.
EXAMPLE
Filename expansion:
rm *; ls ??; cat file[1-3];
Quotes protect metacharacter:
echo "How are you?"
03. SHELL VARIABLES :
Shell variables change during the execution of the program .The C Shell offers a
command "Set" to assign a value to a variable.
For example:
% set myname= Fred
% set myname = "Fred Bloggs"
% set age=20
A $ sign operator is used to recall the variable values.
For example:
% echo $myname will display Fred Bloggs on the screen
A @ sign can be used to assign the integer constant values.
For example:
%@myage=20
%@age1=10
%@age2=20
%@age=$age1+$age2
%echo $age
List variables
% set programming_languages= (C LISP)
% echo $programming _languages
C LISP
% set files=*.*
% set colors=(red blue green)
% echo $colors[2]
blue
18. Operating System Lab Manual
Page 18
% set colors=($colors yellow)/add to list
Local variables Local variables are in scope for the current shell. When a script ends, they
are no longer available; i.e., they go out of scope. Local variables are set
and assigned values.
EXAMPLE
variable_name=value
name="John Doe" x=5
Global variables Global variables are called environment variables. They are set for the currently
running shell and any process spawned from that shell. They go out of scope when
the script ends.
EXAMPLE
VARIABLE_NAME=value
export VARIABLE_NAME
PATH=/bin:/usr/bin:.
export PATH
Extracting values from variables To extract the value from variables, a dollar sign is used.
EXAMPLE
echo $variable_name
echo $name echo
$PATH
Rules : -
1.A variable name is any combination of alphabets, digits and an underscore („-„);
2.No commas or blanks are allowed within a variable name.
3.The first character of a variable name must either be an alphabet or an underscore
4.Variables names should be of any reasonable length.
5.Variables name are case sensitive . That is , Name, NAME, name, NAme, are all
different variables.
04. EXPRESSION Command :
To perform all arithematic operations .
Syntax :
Var = „expr$value1‟ + $ value2‟
Arithmetic The Bourne shell does not support arithmetic. UNIX/Linux commands
must be used to perform calculations.
19. Operating System Lab Manual
Page 19
EXAMPLE
n=`expr 5 + 5` echo
$n
Operators The Bourne shell uses the built-in test command operators to test numbers and
strings.
EXAMPLE
Equality:
= string
!= string
-eq number
-ne number
Logical:
-a and
-o or
! not
Logical:
AND &&
OR ||
Relational:
-gt greater than
-ge greater than, equal to
-lt less than
-le less than, equal to
Arithmetic :
+, -, *, /, %
Arguments (positional parameters) Arguments can be passed to a script from the command line.
Positional parameters are used to receive their values from within the script.
EXAMPLE
At the command line:
$ scriptname arg1 arg2 arg3 ...
In a script:
echo $1 $2 $3 Positional parameters
echo $* All the positional paramters
echo $# The number of positional parameters
20. Operating System Lab Manual
Page 20
05.READ Statement :
To get the input from the user.
Syntax :
read x y
(no need of commas between variables)
06. ECHO Statement :
Similar to the output statement. To print output to the screen, the echo command is used.
Wildcards must be escaped with either a backslash or matching quotes.
Syntax :
Echo “String” (or) echo $ b(for variable).
EXAMPLE
echo "What is your name?"
Reading user input The read command takes a line of input from the user and assigns it to
a variable(s) on the right-hand side. The read command can accept muliple variable names.
Each variable will be assigned a word.
EXAMPLE
echo "What is your name?"
read name read name1
name2 ...
6. CONDITIONAL STATEMENTS :
The if construct is followed by a command. If an expression is to be tested, it is enclosed in
square brackets. The then keyword is placed after the closing parenthesis. An if must end with a fi.
Syntax :
1.if
This is used to check a condition and if it satisfies the condition if then does the next
action , if not it goes to the else part.
2.if…else
Syntax :
If cp $ source $ target
Then
Echo File copied successfully
Else
Echo Failed to copy the file.
3.nested if
here sequence of condition are checked and the corresponding performed
accordingly.
21. Operating System Lab Manual
Page 21
Syntax :
if condition
then
command
if condition
then
command
else
command
fi
fi
4.case ….. esac
This construct helps in execution of the shell script based on
Choice:
EXAMPLE
The if construct is:
if command
then
block of statements
fi
--------------------------------------
if [ expression ]
then
block of statements
fi
--------------------------------------
The if/else/else if construct is:
if command
then
block of statements
elif command
then
block of statements
elif command
then
block of statements
else
block of statements
fi
------------------------------
22. Operating System Lab Manual
Page 22
if [ expression ]
then
block of statements
elif [ expression ]
then
block of statements
elif [ expression ]
then
block of statements
else
block of statements
fi
The case command construct is:
case variable_name in
pattern1)
statements
;;
pattern2)
statements
;;
pattern3)
;;
*) default value ;;
esac
case "$color" in
blue)
echo $color is blue ;;
green)
echo $color is green ;;
red|orange)
echo $color is red or orange ;;
*) echo "Not a color" # default esac
--------------------------------------
The if/else construct is:
if [ expression ]
then
block of statements
else
block of statements
fi
--------------------------------------
23. Operating System Lab Manual
Page 23
07. LOOPS
There are three types of loops: while, until and for. The while loop is followed by a command or
an expression enclosed in square brackets, a do keyword, a block of statements, and terminated with the
done keyword. As long as the expression is true, the body of statements between do and done will be
executed.
The until loop is just like the while loop, except the body of the loop will be executed as long as the
expression is false.
The for loop used to iterate through a list of words, processing a word and then shifting it off, to process
the next word. When all words have been shifted from the list, it ends. The for loop is followed by a
variable name, the in keyword, and a list of words then a block of statements, and terminates with the
done keyword.
The loop control commands are break and continue.
EXAMPLE
while command
do
block of statements
done
------------
while [ expression ]
do
block of statements
done
-----
until [ expression ]
do
block of statements
done
------------
until control command
do
commands
done
08. Break Statement :
This command is used to jump out of the loop instantly, without waiting to get the control
command.
09. ARRAYS
24. Operating System Lab Manual
Page 24
(positional parameters) The Bourne shell does support an array, but a word list can be created by
using positional parameters. A list of words follows the built-in set command, and
the words are accessed by position. Up to nine positions are allowed.The built-in
shift command shifts off the first word on the left-hand side of the list. The
individual words are accessed by position values starting at 1.
EXAMPLE
set word1 word2 word3
echo $1 $2 $3 Displays word1, word2, and word3
set apples peaches plums
shift Shifts off apples
echo $1 Displays first element of the list
echo $2 Displays second element of the list
echo $* Displays all elements of the list
Command substitution To assign the output of a UNIX/Linux command to a variable, or use
the output of a command in a string, backquotes are used.
EXAMPLE
variable_name=`command`
echo $variable_name now=`date`
echo $now
echo "Today is `date`"
10. FILE TESTING
The Bourne shell uses the test command to evaluate conditional expressions and has a built-in
set of options for testing attributes of files, such as whether it is a directory, a plain file (not a directory),
a readable file, and so forth.
EXAMPLE
-d File is a directory
-f File exists and is not a directory
–r Current user can read the file
–s File is of nonzero size
–w Current user can write to the file
–x Current user can execute the file
#!/bin/sh
1 if [ –f file ]
then
echo file exists
fi
2 if [ –d file ]
then echo file is a directory
fi
25. Operating System Lab Manual
Page 25
3 if [ -s file ]
then
echo file is not of zero length
fi
4 if [ -r file -a -w file]
then
echo file is readable and writable
fi
11. EXECUTION OF SHELL SCRIPT :
1.By using change mode command
2.$ chmod u + x sum.sh
3.$ sum.sh or
$ sh sum.sh
RESULT:
SHELL PROGRAMMING
Ex.No :2a CONCATENATION OF TWO STRINGS
Date:
Aim:
To write a shell program to concatenate two strings.
Algorithm:
Step1: Enter into the vi editor and go to the insert mode for entering the code
Step2: Read the first string.
Step3: Read the second string
Step4: Concatenate the two strings
Step5: Enter into the escape mode for the execution of the result and verify the output
Program:
echo “enter the first string”
read str1
26. Operating System Lab Manual
Page 26
echo “enter the second string”
read str2
echo “the concatenated string is” $str1$str2
Sample I/P:
Enter first string: Hello
Enter first string: World
Sample O/P:
The concatenated string is HelloWorld
Result:
Thus the shell program to concatenate two strings is executed and output is verified
successfully.
Ex.No. :2b COMPARISON OF TWO STRINGS
Date:
Aim:
To write a shell program to compare the two strings.
Algorithm:
Step1: Enter into the vi editor and go to the insert mode for entering the code
Step2: Read the first string.
Step3: Read the second string
Step4: Compare the two strings using the if loop
Step5: If the condition satisfies then print that two strings are equal else print two
strings are not equal.
Step6: Enter into the escape mode for the execution of the result and verify the output
Program:
27. Operating System Lab Manual
Page 27
echo “enter the first string”
read str1
echo “enter the second string”
read str2
if [ $str1 = $str2 ]
then
echo “strings are equal”
else
echo “strings are unequal”
fi
Sample I/P:1
Enter first string: hai
Enter second string: hai
Sample O/P:1
The two strings are equal
Sample I/P:2
Enter first string: hai
Enter second string: cse
Sample O/P:2
The two strings are not equal
Result:
Thus the shell program to compare the two strings is executed and output is verified
successfully.
Ex.No:2c MAXIMUM OF THREE NUMBERS
Date:
Aim:
To write a shell program to find greatest of three numbers.
Algorithm:
Step1: Declare the three variables.
Step2: Check if A is greater than B and C.
Step3: If so print A is greater.
Step4: Else check if B is greater than C.
Step5: If so print B is greater.
Step6: Else print C is greater.
28. Operating System Lab Manual
Page 28
Program:
echo "enter A"
read a
echo "enter B"
read b
echo "enter C"
read c
if [ $a -gt $b -a $a -gt $c ]
then
echo "A is greater"
elif [ $b -gt $a -a $b -gt $c ]
then
echo "B is greater"
else
echo "C is greater"
fi
Sample I/P:
Enter A:23
Enter B:45
Enter C:67
Sample O/P:
C is greater
Result:
Thus the shell program to find the maximum of three numbers is executed and output is
verified successfully.
Ex.No:2d FIBONACCI SERIES
Date:
Aim:
To write a shell program to generate fibonacci series.
Algorithm :
Step 1 : Initialise a to 0 and b to 1.
29. Operating System Lab Manual
Page 29
Step 2 : Print the values of 'a' and 'b'.
Step 3 : Add the values of 'a' and 'b'. Store the added value in variable 'c'.
Step 4 : Print the value of 'c'.
Step 5 : Initialise 'a' to 'b' and 'b' to 'c'.
Step 6 : Repeat the steps 3,4,5 till the value of 'a' is less than 10.
Program :
echo enter the number
read n
a=-1
b=1
i=0
while [ $i –le $n ]
do t=`expr $a +
$b` echo $t a=$b
b=$t i=`expr $i +
1 done
Sample I/P :
Enter the no: 5
Sample O/P:
0
1
1
2
3
5
Result :
Thus the shell program to find the fibonacci series is executed and output is
verified successfully.
Ex.No:2e ARITHMETIC OPERATIONS USING CASE
Date:
Aim:
To write a shell program to perform the arithmetic operations using case
Algorithm :
30. Operating System Lab Manual
Page 30
Step 1 : Read the input variables and assign the value
Step 2 : Print the various arithmetic operations which we are going to perform
Step 3 : Using the case operator assign the various functions for the arithmetic
operators.
Step 4 : Check the values for all the corresponding operations.
Step 5 : Print the result and stop the execution.
.
Program :
echo 1.Addition
echo 2.Subraction
echo 3.Multiplication
echo 4.Division
echo enter your choice
read a
echo enter the value of b
read b
echo enter the value of c
read c
echo b is $b c is $c
case $a in
1)d=`expr $b + $c`
echo the sum is $d ;;
2)d=`expr $b - $c`
echo the difference is $d ;;
3)d=`expr $b * $c`
echo the product is $d ;;
4)d=`expr $b / $c`
echo the quotient is $d ;;
esac
Sample I/P :
1.Addition
2.Subraction
3.Multiplication
Division
Enter your choice:1
Enter the value of b:3
Enter the value of c:4
31. Operating System Lab Manual
Page 31
b is 3 c is 4
the sum is 7
Sample O/P:
b is 3 c is 4 the
sum is 7
Result :
Thus the shell program to perform arithmetic operations using case is executed and
output is verified successfully.
SYSTEM CALLS
Ex.No:3a PROCESS CREATION
Date:
AIM:
To write a program to create a process in UNIX.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Declare pid as integer.
STEP 3: Create the process using Fork command.
STEP 4: Check pid is less than 0 then print error else if pid is equal to 0 then execute
command else parent process wait for child process.
STEP 5: Stop the program.
PROGRAM:
void main()
{
int id;
id=fork();
if(id<0)
{
Printf(“cannot create the file”);
Exit(-1);
}
if(id==0)
{
Printf(“child process”);
Exit(0);
32. Operating System Lab Manual
Page 32
}
else
{
Printf(“parent process”);
}
}
SAMPLE OUTPUT:
$cc pc.c
$a.out
parent process$ child process
$ps
PID CLS PRI TTY TIME COMD
5913 TS 70 pts022 0:00 ksh
6229 TS 59 pts022 0:00 ps
RESULT:
Thus the program was executed and verified successfully
Ex.No:3b EXECUTING A COMMAND
Date:
AIM:
To write a program for executing a command.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Execute the command in the shell program using exec ls.
STEP 3: Stop the execution.
PROGRAM:
echo Program for executing UNIX command using shell programming
echo Welcome
ps
exec wc e
SAMPLE OUTPUT:
33. Operating System Lab Manual
Page 33
$ sh exec.sh
program for executing UNIX command using shell programming
Welcome
PID CLS PRI TTY TIME COMD
958 TS 70 pts001 0:00 ksh
971 TS 70 pts001 0:00 sh
972 TS 59 pts001 0:00 ps
3 41 81 e
RESULT:
Thus the program was executed and verified successfully.
Ex.No:3c SLEEP COMMAND
Date:
AIM:
To create child with sleep command.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Create process using fork and assign into a variable.
STEP 3: If the value of variable is < zero print not create and > 0 process create and
else print child create.
STEP 4: Create child with sleep of 2.
STEP 5: Stop the program.
PROGRAM:
void main()
{
34. Operating System Lab Manual
Page 34
int id=fork();
if(id==-1) {
printf(“cannot create the file”);
exit(1);
}
else if(id==0)
{
sleep(2);
printf(“this is child process”);
}
else
{
printf(“parent process”);
exit(1);
}
}
OUTPUT:
$ cc sleep.c
$ a.out
parent process$ this is child process
RESULT:
Thus the program was executed and verified successfully.
Ex.No:3d SLEEP COMMAND USING GETPID
Date:
AIM:
35. Operating System Lab Manual
Page 35
To create child with sleep command using getpid.
ALGORITHM:
STEP 1: Start the execution and create a process using fork() command.
STEP 2: Make the parent process to sleep for 10 seconds.
STEP 3:In the child process print it pid and it corresponding pid.
STEP 4: Make the child process to sleep for 5 seconds.
STEP 5: Again print it pid and it parent pid.
STEP 6: After making the sleep for the parent process for 10 seconds print it pid.
STEP 7: Stop the execution.
PROGRAM:
void main()
{
int pid;
pid=fork();
if (pid==0)
{
printf(“n Child Processn”);
printf(“n Child Process id is %d ”,getpid());
printf(“n Its parent process id is %d”,getppid());
sleep(5);
printf(“Child process after sleep=5n”);
printf(“n Child Process id is %d ”,getpid());
printf(“n Its parent process id is %d”,getppid());
}
else
{
36. Operating System Lab Manual
Page 36
printf(“nParent process”);
sleep(10);
printf(“n Child Process id is %d ”,getpid());
printf(“n Its parent process id is %d”,getppid());
printf(“nParent terminatesn”);
}
}
OUTPUT:
$ cc sleepid.c
$ a.out
parent process
child process
child process id is 12691
its parent process id is 12690
child process after sleep=5
child process id is 12691
its parent process id is 12690
child process after sleep=10
child id is 12690
parent id is 11383
parent terminates
$
RESULT:
Thus the program was executed and verified successfully.
37. Operating System Lab Manual
Page 37
Ex.No:3e SIGNAL HANDLING
Date:
AIM:
To write a program for signal handling in UNIX.
ALGORITHM:
STEP 1:start the program
STEP 2:Read the value of pid.
STEP 3:Kill the command surely using kill-9 pid.
STEP 4:Stop the program.
PROGRAM:
echo program for performing KILL operations
ps
echo enter the pid
read pid
kill-9 $pid
echo finished
OUTPUT:
$sh kill.sh
program for performing KILL operations
PID CLS PRI TTY TIME COMD
858 TS 70 pts001 0:00 ksh
858 TS 70 pts001 0:00 sh
858 TS 59 pts001 0:00 ps
enter the pid 872
killed
$sh kill.sh
program for performing KILL operations
38. Operating System Lab Manual
Page 38
PID CLS PRI TTY TIME COMD
858 TS 70 pts001 0:00 ksh
858 TS 70 pts001 0:00 sh
858 TS 59 pts001 0:00 ps
enter the pid
876
UX:kill(kill.sh):ERROR: no such proccess
$sh kill.sh
program for performing KILL operations
PID CLS PRI TTY TIME COMD
858 TS 70 pts001 0:00 ksh
858 TS 70 pts001 0:00 sh
858 TS 59 pts001 0:00 ps
enter the pid
858
finished
RESULT:
Thus the program was executed and verified successfully.
Ex.No:3f WAIT COMMAND
Date:
AIM:
To perform wait command using c program.
ALGORITHM:
39. Operating System Lab Manual
Page 39
STEP 1:Start the execution
STEP 2:Create process using fork and assign it to a variable
STEP 3:Check for the condition pid is equal to 0
STEP 4:If it is true print the value of i and teriminate the child process
STEP 5:If it is not a parent process has to wait until the child teriminate
STEP 6:Stop the execution
PROGRAM:
int i=10;
void main()
{
int pid=fork();
if(pid==0)
{
printf(“initial value of i %d n “,i);
i+=10;
printf(“value of i %d n “,i);
printf(“child terminated n”);
}
else
{
wait(0);
printf(“value of i in parent process %d”,i);
}
}
OUTPUT:
$cc wait.c
$a.out
40. Operating System Lab Manual
Page 40
initial value of i 10
value of i 20
child teriminated
value of i in parent process 10$
RESULT:
Thus the program was executed and verified successfully.
ExNo:4a READING FROM A FILE
Date:
AIM:
To create the file,read data from the file,update the file.
ALGORITHM:
1.Get the data from the user.
2.Open a file.
3.Read from the file.
4.Close the file.
PROGRAM:
#include<stdio.h> int
main()
{
char str[100];
FILE *fp;
fp=fopen("file1.dat","r");
while(!feof(fp))
{ fscanf(fp,"%s",str);
printf(" %s ",str);
}
fclose(fp);
}
41. Operating System Lab Manual
Page 41
OUTPUT:
$ vi read1.c
$gcc read1.c
$ ./a.out hai this is a program to read the content of the file.
RESULT:
Thus C program to write data into a file was executed successfully
ExNo:4b WRITING INTO A FILE
Date
AIM:
To write a C program to write the data into a file.
ALGORITHM:
Step1.Get the data from the user.
Step2.Open a file.
Step3.Write the data from the file.
Step4.Get the data and update the file.
PROGRAM:
#include<stdio.h> int
main()
{ char str[100]; FILE
*fp;
printf("Enter the string"); gets(str);
fp=fopen("file1.dat","w+"); while(!feof(fp))
{ fscanf(fp,"%s",str);
}
fprintf(fp,"%s",str);
}
OUTPUT:
$ gcc write.c
$ ./a.out
Enter the string: os lab
$vi file1.dat
os lab
RESULT:
Thus C program to write data into a file was executed successfully.
42. Operating System Lab Manual
Page 42
ExNo:4c FILE CREATION
Date:
AIM:
To write a C program to create a file.
ALGORITHM:
Step1:Start the program.
Step2:Create the file using create function and assign a variable to it.
Step3:If the value of the variable is less then print file cannot be created ,otherwise
print file is created.
Step4:Stop the program.
PROGRAM:
void main()
{
int id;
if(id=creat(“z.txt”,0)==-1)
{ printf(“cannot create the file”);
exit(1);
} else
{
printf(“file is created”);
exit(1);
}
}
OUTPUT:
$ cc fc.c $ a.out
file is created $
RESULT:
Thus the C program to create a file was executed successfully.
43. Operating System Lab Manual
Page 43
Ex. No:5a IMPLEMENTATION OF ls COMMAND
Date:
AIM:
To write a C program to simulate the operation of “ls” command in Unix.
ALGORITHM:
1. Check if the number of command line arguments is less than 2. If yes, Print error
and exit.
2. Check if the second argument (i.e. directory to be listed) is valid or not. If not then
exit.
3. Print the content of the directory till it becomes NULL.
4. Close the directory entry file.
PROGRAM:
#include<stdio.h>
#include<sys/types.h>
#include<dirent.h> main(int
argc, char *argv[])
{
DIR *dp; struct
dirent *dirp;
if(argc<2)
{
printf("n You have provided only 1 argumentn");
exit(1);
}
if((dp=opendir(argv[1]))==NULL)
{
printf("nCannot open %s file!n",argv[1]);
exit(1);
}
while((dirp=readdir(dp))!=NULL)
printf("%sn",dirp->d_name);
closedir(dp);
}
OUTPUT:
[root@lab1]# gcc lsdemo.c
[root@lab1]# ./a.out
44. Operating System Lab Manual
Page 44
You have provided only 1 argument
[root@lab1]# ./a.out /xyz/foo
Cannot open /xyz/foo file!
[root@lab1]# ./a.out /root
[root@lab1]# ./a.out /tmp/orbit
. ..
sem.c
first.c
best.c
a.out
lsdemo.c
roundrobin.c
bestop.doc
firstop.doc
roundrobin.doc
[root@lab1]#
RESULT:
Thus the program for implementing the ls command was executed and the output was
verified successfully.
ExNo:6a FIRST COME FIRST SERVE
Date :
AIM:
To write a C program to implement the CPU scheduling algorithm for FIRST
COME FIRST SERVE.
PROBLEM DESCRIPTION:
Cpu scheduler will decide which process should be given the CPU for its execution.For this
it use different algorithm to choose among the process. one among that algorithm is fcfs
algorithm.
45. Operating System Lab Manual
Page 45
In this algorithm the process which arrive first is given the cpu after finishing its request
only it will allow cpu to execute other process.
ALGORITHM:
Step1: Create the number of process.
Step2: Get the ID and Service time for each process.
Step3: Initially, Waiting time of first process is zero and Total time for the first
process is the starting time of that process.
Step4: Calculate the Total time and Processing time for the remaining processes.
Step5: Waiting time of one process is the Total time of the previous process.
Step6: Total time of process is calculated by adding Waiting time and Service time.
Step7: Total waiting time is calculated by adding the waiting time for lack process.
Step8: Total turn around time is calculated by adding all total time of each process.
Step9: Calculate Average waiting time by dividing the total waiting time by total
number of process.
Step10: Calculate Average turn around time by dividing the total time by the
number of process.
Step11: Display the result.
PROGRAM
#include<stdio.h> struct
process
{
int id,wait,ser,tottime;
}p[20];
main() {
int i,n,j,totalwait=0,totalser=0,avturn,avwait;
printf("enter number of process");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
46. Operating System Lab Manual
Page 46
printf("enter process_id");
scanf("%d",&p[i].id);
printf("enter process service time");
scanf("%d",&p[i].ser);
}
p[1].wait=0;
p[1].tottime=p[1].ser;
for(i=2;i<=n;i++)
{
for(j=1;j<i;j++)
{
p[i].wait=p[i].wait+p[j].ser;
}
totalwait=totalwait+p[i].wait;
p[i].tottime=p[i].wait+p[i].ser;
totalser=totalser+p[i].tottime;
}
avturn=totalser/n;
avwait=totalwait/n;
printf("Idtservicetwaitttotal");
for(i=1;i<=n;i++)
{
printf("n%dt%dt%dt%dn",p[i].id,p[i].ser,p[i].wait,p[i].tottime);
}
printf("average waiting time %dn",avwait);
printf("average turnaround time %dn",avturn);
}
OUTPUT
[admin@lab1]$ gcc fcfs.c
[admin@lab1]$ ./a.out
enter number of process4
enter process_id901
enter process service time4
enter process_id902
enter process service time3
enter process_id903
47. Operating System Lab Manual
Page 47
enter process service time5
enter process_id904
enter process service time2
Id service wait total
901 4 0 4
902 3 4 7
903 5 7 12
904 2 12 14
average waiting time 5
average turnaround time 8
RESULT:
Thus the C program to implement CPU scheduling algorithm for first come first
serve was executed successfully.
ExNo:6b SHORTEST JOB FIRST
Date :
AIM:
To write a C program to implement the CPU scheduling algorithm for Shortest job first.
PROBLEM DESCRIPTION:
Cpu scheduler will decide which process should be given the CPU for its execution. For
this it use different algorithm to choose among the process. one among that algorithm is sjf
algorithm.
In this algorithm the process which has less service time given the cpu after finishing its
request only it will allow cpu to execute next other process.
ALGORITHM:
Step1:Get the number of process.
Step2:Get the id and service time for each process.
Step3:Initially the waiting time of first short process as 0 and total time of first
short is process the service time of that process.
48. Operating System Lab Manual
Page 48
Step4:Calculate the total time and waiting time of remaining process.
Step5:Waiting time of one process is the total time of the previous process.
Step6:Total time of process is calculated by adding the waiting time and service
time of each process.
Step7:Total waiting time calculated by adding the waiting time of each process.
Step8:Total turn around time calculated by adding all total time of each process.
Step9:calculate average waiting time by dividing the total waiting time by total
number of process.
Step10:Calculate average turn around time by dividing the total waiting time by
total number of process.
Step11:Display the result.
PROGRAM:
#include<stdio.h>
struct ff {
int pid,ser,wait;
}p[20];
struct ff tmp; main() { int
i,n,j,tot=0,avwait,totwait=0,tturn=0,aturn;
printf("enter the number of process");
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("enter process id");
scanf("%d",&p[i]);
printf("enter service time");
scanf("%d",&p[i].ser);
p[i].wait=0; }
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(p[i].ser>p[j].ser)
49. Operating System Lab Manual
Page 49
{ tmp=p[i];
p[i]=p[j];
p[j]=tmp;
}
}
}
printf("PIDtSERtWAITtTOTn");
for(i=0;i<n;i++)
{ tot=tot+p[i].ser; tturn=tturn+tot; p[i+1].wait=tot;
totwait=totwait+p[i].wait;
printf("%dt%dt%dt%dn",p[i].pid,p[i].ser,p[i].wait,tot);
}
avwait=totwait/n;
aturn=tturn/n;
printf("TOTAL WAITING TIME :%dn",totwait);
printf("AVERAGE WAITING TIME : %dn",avwait);
printf("TOTAL TURNAROUND TIME :%dn",tturn);
printf("AVERAGE TURNAROUND TIME:%dn",aturn);
}
OUTPUT :
[root@lab1]# ./a.out
enter the number of process4
enter process id701
enter service time6
enter process id702
enter service time4
enter process id703
enter service time8
enter process id704
enter service time1
PID SER WAIT TOT
704 1 0 1
702 4 1 5
701 6 5 11
703 8 11 19
TOTAL WAITING TIME :17
AVERAGE WAITING TIME : 4
TOTAL TURNAROUND TIME :36
AVERAGE TURNAROUND TIME:9
50. Operating System Lab Manual
Page 50
Result:
Thus the C program to implement the CPU scheduling algorithm for shortest job first
was executed successfully.
51. Operating System Lab Manual
Page 51
Ex.No :7a ROUND ROBIN Date:
AIM :
To write a C program to simulate the CPU scheduling algorithm for round robin
PROBLEM DESCRIPTION:
CPU scheduler will decide which process should be given the CPU for its execution .For
this it use different algorithm to choose among the process .one among that algorithm is Round
robin algorithm.
In this algorithm we are assigning some time slice .The process is allocated according to the
time slice ,if the process service time is less than the time slice then process itself will release
the CPU voluntarily .The scheduler will then proceed to the next process in the ready queue .If
the CPU burst of the currently running process is longer than time quantum ,the timer will go off
and will cause an interrupt to the operating system .A context switch will be executed and the
process will be put at the tail of the ready queue.
ALGORITHM:
Step 1: Initialize all the structure elements
Step 2: Receive inputs from the user to fill process id,burst time and arrival time.
Step 3: Calculate the waiting time for all the process id.
i) The waiting time for first instance of a process is calculated as:
a[i].waittime=count + a[i].arrivt
ii) The waiting time for the rest of the instances of the process is
calculated as:
a) If the time quantum is greater than the remaining
burst time then waiting time is calculated as:
a[i].waittime=count + tq
b) Else if the time quantum is greater than the
remaining burst time then
waiting time is calculated as:
a[i].waittime=count - remaining burst time
Step 4: Calculate the average waiting time and average turnaround time
Step 5: Print the results of the step 4.
PROGRAM
/*
52. Operating System Lab Manual
Page 52
This program has assumed that the inputs are given in ordered fashion according to their
arrival times.
*/
struct roundRobin
{
int pburst,pburst1,wtime,endtime,arrivt,boolean,flagcntl;
char pname[5];
}a[5];
int n,tq; void
input(); void
initialize(); void
calculate();
void display_waittime();
int main() { input();
initialize();
calculate();
display_waittime();
//getch();
//return 0;
}
void input() { int
i;
printf("Enter Total no. of processesn");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter process name:");
scanf("%s",&a[i].pname);
printf("Enter process burst time:");
scanf("%d",&a[i].pburst); printf("Enter
process arrival time:");
scanf("%d",&a[i].arrivt);
}
printf("nEnter the time quantum/Time Slice:");
scanf("%d",&tq);
}
53. Operating System Lab Manual
Page 53
void initialize()
{ int i;
for(i=0;i<n;i++)
{
a[i].pburst1=a[i].pburst;
a[i].wtime=0; a[i].endtime=0;
a[i].boolean=0;
a[i].flagcntl=0;
}
}
void calculate()
{ int i,j=0,k=0,flag=1,count=0;
printf("n---GANTT CHART---n");
printf("0 | ");
while(flag)
{
for(i=0;i<n;i++)
{
if((k<n)&&(a[i].arrivt<=count)&&(a[i].flagcntl==0)) //calculating waiting time for first
time
{
a[i].wtime=count-a[i].arrivt;
a[i].endtime=count;
a[i].boolean=1;
a[i].flagcntl=1; k++;
}
if((a[i].pburst1>tq)&&(a[i].arrivt<=count))
{
if(a[i].boolean==1) a[i].boolean=0;
else
a[i].wtime=a[i].wtime+(count-a[i].endtime);
count=count+tq; a[i].pburst1=a[i].pburst1-tq;
a[i].endtime=count;
printf("%d %s| ",count,a[i].pname);
}
else if((a[i].pburst1>0) && (a[i].pburst1<=tq) && (a[i].arrivt<=count))
{
if(a[i].boolean==1)
54. Operating System Lab Manual
Page 54
a[i].boolean=0;
else
a[i].wtime=a[i].wtime+(count-a[i].endtime);
count=count+a[i].pburst1;
a[i].endtime=count; printf("%d %s|
",count,a[i].pname);
a[i].pburst1=0;
j++;
}
else if(j==n) flag=0;
}//end of for loop
}//end of while loop
}
void display_waittime()
{ int i,tot=0,turn=0;
for(i=0;i<n;i++)
{
printf("nnWaiting time for Process %s is %d",a[i].pname,a[i].wtime);
tot=tot+a[i].wtime;
turn=turn+a[i].endtime-a[i].arrivt;
}
printf("nntAverage waiting time=%f",(float)tot/(float)n);
printf("ntAverage turnaround time=%fn",(float)turn/(float)n);
}
OUTPUT:
[root@lab1]# gcc roundrobin.c
[root@lab1]# ./a.out
Enter Total no. of processes
3
Enter process name:A
Enter process burst time:4
Enter process arrival time:0
Enter process name:B
Enter process burst time:3
55. Operating System Lab Manual
Page 55
Enter process arrival time:3
Enter process name:C
Enter process burst time:2
Enter process arrival time:3
Enter the time quantum/Time Slice:2
---GANTT CHART---
0 | 2 A| 4 A| 6 B| 8 C| 9 B|
Waiting time for Process A is 0
Waiting time for Process B is 3
Waiting time for Process C is 3
Average waiting time=2.000000
Average turnaround time=5.000000
[root@lab1]#
RESULT:
Thus the C program to simulate CPU scheduling algorithm for round robin was
executed successfully.
ExNo:7b PRIORITY SCHEDULING
Date:
AIM:
To write a C program to implement CPU scheduling algorithm for priority scheduling.
PROBLEM DESCRIPTION:
Cpu scheduler will decide which process should be given the CPU for its execution.For this
it use different algorithm to choose among the process. one among that algorithm is fcfs
algorithm.
56. Operating System Lab Manual
Page 56
In this algorithm the process which arrive first is given the cpu after finishing its request
only it will allow cpu to execute other process.
ALGORITHM:
Step1:Get the number of process,burst time and priority.
Step2:Using for loopi=0 to n-1 do step 1 to 6.
Step3:If i=0,wait time=0,T[0]=b[0];
Step4:T[i]=T[i-1]+b[i] and wt[i]=T[i]-b[i].
Step5: Total waiting time is calculated by adding the waiting time for lack process.
Step6: Total turn around time is calculated by adding all total time of each process.
Step7: Calculate Average waiting time by dividing the total waiting time by total number of process.
Step8: Calculate Average turn around time by dividing the total time by the number of process.
Step9: Display the result.
PROGRAM:
void main()
{
int i,j,n,t,turn[20],burst[20],p[20],wt[20],c[20];
float await,aturn,twait=0,tturn=0; printf(“nEnter the
value of n:”); scanf(“%d”,&n);
printf(“n Enter the process no burst and arrivaltime”); for(i=0;i<n;i++)
{
scanf(“%d”,&c[i]);
scanf(“%d”,&burst[i]);
scanf(“%d”,&p[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(p[i]>p[j])
{
t=p[i];
p[i]=p[j];
57. Operating System Lab Manual
Page 57
p[j]=t;
t=burst[i];
burst[i]=burst[j];
burst[j]=t;
t=c[i];
c[i]=c[j];
c[j]=t;
}
}
for(i=0;i<n;i++)
{
if(i==0)
{
wt[i]=0;
turn[i]=burst[i];
}
}
else
{
turn[i]=turn[i-1]+burst[i];
wt[i]=turn[i]-burst[i];
twait=twait+wt[i];
tturn=tturn+turn[i];
}
await=twait/n;
aturn=tturn/n;
printf(“pnotbtimetatimetwtimetttime”);
for(i=0;i<n;i++)
{
printf(“n%dt%dt%dt%dt%dn”,c[i],burst[i],p[i],wt[i],turn[i]);
}
printf(“n The average waiting time is:%f”,await);
printf(“n The average turn around time is:%f”,aturn);
}
OUTPUT:
$$ cc ps.c
$a.out
58. Operating System Lab Manual
Page 58
Enter the process burst no and priority
1 15 2
2 5 1 3
10
3
pno btime priority wtime ttime
2 5 1 0 5
1 15 2 5 20
3 10 3 20 30
The average waiting time is :8.333333
The average turn around time is:18.333334
RESULT:
Thus C program to implement CPU scheduling algorithm for priority scheduling
was executed successfully.
ExNo:8 PRODUCER CONSUMER PROBLEM USING SEMAPHORE
Date :
AIM:
To write a C program to implement the Producer & consumer Problem (Semaphore)
ALGORITHM:
Step 1: The Semaphore mutex, full & empty are initialized.
Step 2: In the case of producer process
i) Produce an item in to temporary variable.
ii) If there is empty space in the buffer check the mutex value for enter into the critical
section.
iii) If the mutex value is 0, allow the producer to add value in the temporary variable to the
buffer.
Step 3: In the case of consumer process
i) It should wait if the buffer is empty
ii) If there is any item in the buffer check for mutex value, if the mutex==0, remove item
from buffer
iii) Signal the mutex value and reduce the empty value by 1.
iv) Consume the item.
Step 4: Print the result
59. Operating System Lab Manual
Page 59
PROGRAM :
#define BUFFERSIZE 10 int
mutex,n,empty,full=0,item,item1;
int buffer[20];
int in=0,out=0,mutex=1;
void wait(int s)
{
while(s<0)
{
printf(“nCannot add an itemn”);
exit(0);
}
s--; }
void signal(int s)
{
s++; }
void producer()
{
do
{
wait (empty);
wait(mutex);
printf(“nEnter an item:”);
scanf(“%d”,&item);
buffer[in]=item; in=in+1;
signal(mutex);
signal(full);
}
while(in<n);
}
void consumer()
{ do { wait(full); wait(mutex);
item1=buffer[out]; printf(“nConsumed
item =%d”,item1);
out=out+1;
signal(mutex);
signal(empty);
}
while(out<n);
}
void main()
{
printf(“Enter the value of n:”);
scanf(“%d “,&n); empty=n;
while(in<n) producer();
while(in!=out) consumer();
}
60. Operating System Lab Manual
Page 60
OUTPUT:
$ cc prco.c
$ a.out
Enter the value of n :3
Enter the item:2
Enter the item:5
Enter the item:9 consumed
item=2 consumed item=5
consumed item=9
$
RESULT:
Thus the program for solving producer and consumer problem using semaphore was executed
successfully.
Ex.No:9 MEMORY MANAGEMENT SCHEME- PAGING
Date:
AIM:
To write a C program to implement memory management using paging technique.
ALGORITHM:
Step1 : Start the program.
Step2 : Read the base address, page size, number of pages and memory unit.
Step3 : If the memory limit is less than the base address display the memory
limit is less than limit.
Step4 : Create the page table with the number of pages and page address.
Step5 : Read the page number and displacement value.
Step6 : If the page number and displacement value is valid, add the displacement value
with the address corresponding to the page number and display the result.
Step7 : Display the page is not found or displacement should be less than page size.
Step8 : Stop the program.
PROGRAM:
#include<stdio.h>
#include<unistd.h>
61. Operating System Lab Manual
Page 61
void main()
{
int b[20],n,i,pa,p,a,d; printf(“nProgram
for paging”); scanf(“%d”,&n);
printf(“nEnter the base address:”); for(i=0;i<n;i++)
{
scanf(“%d”,&b[i]);
} printf(“nEnter the logical
address:”); scanf(“%d”,&p);
for(i=0;i<n;i++)
{
if(i==p)
{
pa=b[i]+d;
a=b[i];
printf(“ntPageNo.t BaseAdd. PhysicalAdd. nt %d t %d t %d t
”,p,a,pa);
}
} printf(“nInvalid
page”);
}
Sample Input 1:
Program for paging
Enter the number of pages:2
Enter the base address:
100
150
Enter the Logical address:50
Enter the page number:1
Sample Output 1:
PageNo. BaseAdd. PhysicalAdd.
1 150 200
Sample Input 2:
Program for paging
Enter the number of pages:1
Enter the base address:
100
62. Operating System Lab Manual
Page 62
Enter the Logical address:2
Enter the page number:2
Sample Output 2:
Invalid page.
RESULT:
Thus the program for implementing the paging concept was executed and the output
was verified successfully.
Ex.No:10 MEMORY MANAGEMENT SCHEME-SEGMENTATION
Date:
AIM:
To write a C program to implement memory management using segmentation
ALGORITHM:
Step1 : Start the program.
Step2 : Read the base address, number of segments, size of each segment, memory
limit.
Step3 : If memory address is less than the base address display “invalid memory limit”.
Step4 : Create the segment table with the segment number and segment address and
display it.
Step5 : Read the segment number and displacement.
Step6 : If the segment number and displacement is valid compute the real address and
display the same.
Step7 : Stop the program.
PROGRAM:
#include<stdio.h>
#include<unistd.h>
void main()
{
int b[20],l[20],n,i,pa,s,a,d; printf(“nProgram
for segmentation”); printf(“nEnter the
number of segments:”);
scanf(“%d”,&n);
63. Operating System Lab Manual
Page 63
printf(“nEnter the base address and limit register:”); for(i=0;i<n;i++)
{
scanf(“%d”,&b[i]);
scanf(“%d”,&l[i])
}
printf(“nEnter the logical address:”);
scanf(“%d”,&d); for(i=0;i<n;i++)
{
if(i==s)
{
if(d<l[i])
{
pa=b[i]+d;
a=b[i];
printf(“(“ntPageNo.t BaseAdd.
PhysicalAdd. nt %d t %d t
%d t ”,s,a,pa); exit(0);
}
else
{
printf(“nPage size exceeds”);
exit(0);
}
}
} printf(“nInvalid
segment”);
}
Sample Input 1:
Program for segmentation
Enter the number of segments:3
Enter the base address and limit register:
100 50
150 20
130 34
Enter the Logical address:25
Enter the segment number:1
Sample Output 1:
PageNo. BaseAdd. PhysicalAdd.
2 130 155
64. Operating System Lab Manual
Page 64
Sample Input 2:
Program for segmentation
Enter the number of segments:2
Enter the Logical address and limit register:
100 50
150 20
Enter the logical address:25
Enter the segment number:1
Sample Output 2:
page size exceeds
RESULT:
Thus the program for implementing the segmentation concept was executed and the
output was verified successfully.