«
A View of Operating
System Services

· Communications
–Processes may exchange information, on the same computer or between computers
over a network. Communications may be via shared memory or through message passing
(packets moved by the OS)
· Error detection
– OS needs to be constantly aware of possible errors
§ May occur in the CPU and memory hardware, in I/O
devices, in user program
§ For each type of error, OS should take the appropriate
action to ensure correct and consistent computing
§ Debugging facilities can greatly enhance the user’s
and programmer’s abilities to efficiently use the system
· Resource allocation - When
multiple users or multiple jobs running concurrently, resources must be
allocated to each of them. Many types of resources - Some (such as CPU cycles, main memory, and
file storage) may have special allocation code, others (such as I/O devices)
may have general request and release code
· Accounting - To keep
track of which users use how much and what kinds of computer resources
· Protection and
security - The owners of information stored in a multiuser or
networked computer system may want to control use of that information,
concurrent processes should not interfere with each other
§ Protection involves
ensuring that all access to system resources is controlled
§ Security from
outsiders requires user authentication, extends to defending external I/O
devices from invalid access attempts.
§ For a system to be protected and secure, precautions
must be instituted throughout it. A chain is only as strong as its weakest
link.
![]()
« User Operating System Interface
· Command Line Interface (CLI) or command interpreter allows direct command entry
§ Sometimes implemented in kernel, sometimes by systems
program
§ Sometimes multiple flavors implemented – shells
§ Primarily fetches a command from user and executes it
· Sometimes commands built-in, sometimes just names of
programs
If the latter, adding new commands doesn’t require
shell modification.
· User-friendly desktop Graphical User Interface (GUI) metaphor interface
§ Usually mouse, keyboard, and monitor
§ Icons represent files, programs, actions, etc
§ Various mouse buttons over objects in the interface
cause various actions
(provide information, options, execute function, open
directory (folder)
§ Invented at Xerox PARC
· Many systems now include both CLI & GUI interfaces
§ Microsoft Windows is GUI with CLI “command” shell
§ Apple Mac OS has GUI interface with UNIX kernel
underneath and shells available
§ Solaris is CLI with optional GUI interfaces (Java
Desktop, KDE)
![]()
« System Calls
· Programming interface to the services provided by the
OS
· Typically written in a high-level language (C or C++)
· Mostly accessed by programs via a high-level
Application Program Interface (API)
· Three most common APIs are
§ Win32 API for Windows,
§ POSIX API (all versions of UNIX, Linux, and Mac OS),
and
§ Java API for the Java virtual machine (JVM)
Example of System Calls:

Examples:
ęExample 1: copy.c & jcopy.java
Description: Open an existing input file and copy it to non-existing output file.
http://www.cs.odu.edu/~cs471w/code/misc/copy.c
int
main(int argc, char **argv)
{
int n, in, out;
char buf[1024];
char InputFile[1024];
char OutputFile[1024];
struct
stat st;
printf("enter
Input File Name: ");
scanf("%s",
InputFile);
if (stat(InputFile, &st) != 0) {
perror("InputFile does not exit");
exit(1);
}
printf("enter
Outut File Name: ");
scanf("%s",
OutputFile);
if (stat(OutputFile,
&st) == 0) {
perror("OutputFile exists");
exit(1);
}
if ((in = open(InputFile, O_RDONLY))
< 0) {
perror(InputFile);
exit(1);
}
if ((out = open(OutputFile,
O_CREAT | O_WRONLY, 0600)) < 0) {
perror(OutputFile);
exit(1);
}
while ((n = read(in, buf, sizeof(buf))) > 0)
write(out, buf, n);
close(out);
close(in);
printf("copied
%s to %s\n", InputFile, OutputFile);
exit(0);
}
To execute:
% copy
http://www.cs.odu.edu/~cs471w/code/misc/jcopy.java
public class jcopy {
public static
void main(String[] args) throws IOException
{
BufferedReader
stdin
= new BufferedReader( new InputStreamReader(System.in));
System.out.println("enter Input File Name: ");
String InputFile
= stdin.readLine();
File infile
= new File(InputFile);
InputStream
fin = new FileInputStream(infile);
System.out.println("enter
Outut File Name: ");
String OutputFile
= stdin.readLine();
File outfile = new File(OutputFile);
OutputStream
fout
= new FileOutputStream(outfile);
int len;
byte[] buf = new byte[1024];
while ((len = fin.read(buf)) >
0) {
fout.write(buf, 0, len);
}
fin.close();
fout.close();
System.out.println("copied
" + InputFile + " to " + OutputFile);
}
}
To execute:
% java jcopy
ęExample 2: save.c:
Description: save 2nd argument (a string)
into 1st argument file. If the file exists it is truncated, otherwise
it is created.
It then displays the content of the file to tty (standard output or file descriptor 1).
http://www.cs.odu.edu/~cs471w/code/misc/save.c
int
main(int argc, char *argv[])
{
int sfd;
int n;
char buf[1024];
int FileLength;
char *FileName
= argv[1];
char *Message = argv[2];
if ((sfd =
open(FileName, O_RDWR | O_TRUNC| O_CREAT, 0600)) < 0) {
perror(FileName);
exit(1);
}
write(sfd,
Message, strlen(Message));
lseek (sfd,0, SEEK_SET);
printf("\nFile '%s' contains:\n", FileName);
fflush(stdout);
n=read(sfd,
buf, sizeof(buf));
write(1,buf, n);
FileLength
= lseek(sfd, 0, SEEK_END);
printf("\n\nFile '%s' length: '%d'\n", FileName,
FileLength);
}
To execute:
% save savefile
“how are you?”
http://www.cs.odu.edu/~cs471w/code/misc/jsave.java
public class jsave {
public static
void main(String[] args) throws IOException
{
File FileName
= new File(args[0]);
String Message = args[1];
OutputStream
fout
= new FileOutputStream(FileName);
fout.write(Message.getBytes());
System.out.println("File " + FileName +
" contains:");
BufferedReader
fin = new BufferedReader(
new FileReader(FileName));
String str;
while((str = fin.readLine())!= null)
System.out.println(str);
long length = FileName.length();
System.out.println( FileName + " lenght is:
" + length);
}
}
To execute:
% java jsave savefile “how are you?”
API – System Call – OS Relationship

Standard C Library Example:
C program invoking printf()
library call, which calls write() system call

System Call Parameter Passing
Three general methods used to pass parameters to the OS
1. Simplest: pass the parameters in registers
2. Parameters stored in a block,
or table, in memory, and address of block passed as a
parameter in a register. This approach
taken by Linux and Solaris
3. Parameters placed, or pushed, onto the stack
by the program and popped off the stack by the operating
system
Block and stack methods do not limit the number or length of
parameters being passed
Types of System Calls:
ü
Process control
ü
File management
ü
Device management
ü
Information maintenance
ü
Communications
ü
Protection
Examples of Windows and Unix System Calls

![]()
« System Programs
· System programs provide a convenient environment for
program development and execution.
They can be
divided into:
§ File management
§ Status information
§ Programming
language support, loading and
execution.
§ Communications
§ Application
programs
· Most users’ view of operation system is defined by system
programs, not the actual system calls
· Provide a convenient environment for program
development and execution
Some
of them are simply user interfaces to system calls; others are considerably
more complex
· File management - create, delete, copy, rename, print,
dump, list, and generally manipulate files and directories
· Status information
§ system info - date, time, amount of available memory,
disk space, number of users
§ Others provide detailed performance, logging, and
debugging information
§ Typically, these programs format and print the output
to the terminal or other output devices
§ Some systems implement
a registry - used to store and retrieve configuration information
![]()
« Operating System Design and Implementation
·
User goals –
operating system should be convenient to use, easy to learn, reliable, safe,
and fast
·
System goals
– operating system should be easy to design, implement, and maintain, as well
as flexible, reliable, error-free, and efficient
·
Important
principle to separate:
Policy: What will be done?
Mechanism: How to do it?
The
separation of policy from mechanism is a very important principle,
it allows
maximum flexibility if policy decisions are to be changed later
Traditional UNIX System Structure:

UNIX – the
original UNIX operating system had limited structuring.
The UNIX OS
consists of two separable parts
· Systems programs
· The kernel
4 Consists of everything
below the system-call interface and above the physical hardware
4 Provides the file system,
CPU scheduling, memory management, and other operating-system functions; a
large number of functions for one level
![]()
« Virtual Machines
· A virtual machine provides an interface identical
to the underlying bare hardware
· The operating system host creates the
illusion that a process has its own processor and (virtual memory)
· Each guest provided with a (virtual)
copy of underlying computer

VMware Architecture:

The Java Virtual Machine:

![]()
« Operating-System Debugging
· Debugging is finding and fixing errors,
or bugs
· OSs generate log files containing error
information
· Failure of an application can generate core dump file capturing memory of the
process
· Operating system failure can generate
crash dump file containing kernel memory
· Kernighan’s
Law: “Debugging is twice as hard as writing
the code in the first place.
Therefore,
if you write the code as cleverly as possible, you are, by
definition, not smart enough
to debug it.”
![]()
« Operating System Generation
·
Operating
systems are designed to run on any class of machines; the system must be configured for each specific computer
site
·
SYSGEN program obtains information for specific configuration of the hardware system
·
Booting – starting a computer by loading the
kernel
·
Bootstrap
program – code stored
in ROM that is able to locate the kernel, load it into memory, and start its
execution
System Boot:
Operating system must be made available to hardware to start
· Small piece of code – bootstrap
loader, locates the kernel, loads it into memory, and starts it
· Sometimes two-step process where boot
block at fixed location loads bootstrap loader
· When power initialized on system,
execution starts at a fixed memory location