Spos Lab Manual
Spos Lab Manual
Assignment No. 1
Title of Assignment:
Design suitable data structures and implement pass-I of a two-pass
assembler for b bit microprocessor/psedo-machine. Implementation
should consist of a few instruction from each category and few assembler
directives
Problem Statement :
Implement one pass-I of TWO Pass assembler with hypothetical Instruction set
using C language. Instruction set should include all types of assembly
language statements such as Imperative, Declarative and Assembler Directive.
While designing stress should be given on
a) How efficiently Mnemonic opcode table could be implemented so
as to enable faster retrieval on op-code.
b) Implementation of symbol table for faster retrieval.
( Concepts in DSF should be applied while design)
Relevant Theory:
1.
Explain what is meant by pass of an assembler.
2.
Explain the need for two pass assembler.
3.
Explain terms such as Forward Reference and backward reference.
4.
Explain various types of errors that are handled in two different passes.
5.
Explain the need of Intermediate Code generation and the variants used.
6.
State various tables used and their significance in the design of two pass
Assembler.
Implementation Logic:
Tasks performed by the passes of two-pass assembler are as follows:
Pass I: -
1. Separate the symbol, mnemonic opcode and operand fields.
2. Determine the storage-required for every assembly language statement
and update the location counter.
3. Build the symbol table and the literal table.
4. Construct the intermediate code for every assembly language statement.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
1
Software Laboratory
Algorithm/Pseudo code:
Pass I Algorithm (Assembler First Pass)
2
Software Laboratory
{
i. this_addr := value of <address_spec>;
ii. Correct the symbtab entry for this_label to
(this_label,this_addr).
}
c) Go to Pass II.
Testing:
SAMPLE PROGRAM Input
START 200
READ A
READ B
MOVER AREG, ='5'
MOVER AREG, A
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
3
Software Laboratory
ADD AREG, B
SUB AREG, ='6'
MOVEM AREG, C
PRINT C
LTORG
MOVER AREG, ='15'
MOVER AREG, A
ADD AREG, B
SUB AREG, ='16'
DIV AREG, ='26'
MOVEM AREG, C
A DS 1
B DS 1
C DS 1
STOP
END Symbol Table
-------------------------------------------------------------
Symb Addr Decl Used Val Len
-------------------------------------------------------------
A 216 1 1 0 1
B 217 1 1 0 1
C 218 1 1 0 1
-------------------------------------------------------------
Total Errors: 0
Total Warnings: 0
Literal Table
------------------------------------
Lit# Lit Addr
------------------------------------
00 ='5' 208
01 ='6' 209
02 ='15' 220
03 ='16' 221
04 ='26' 222
------------------------------------
Pool Table
--------------------
Pool# Pool Base
--------------------
00 0
01 2
------------------------
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
4
Software Laboratory
INTERMEDIATE CODE
Intermediate Code
(AD, 00) (C, 200)
(IS, 09) (S, 00)
(IS, 09) (S, 01)
(IS, 04) (0) (L, 00)
(IS, 04) (0) (S, 00)
(IS, 01) (0) (S, 01)
(IS, 02) (0) (L, 01)
(IS, 05) (0) (S, 02)
(IS, 10) (S, 02)
(AD, 04)
(IS, 04) (0) (L, 02)
(IS, 04) (0) (S, 00)
(IS, 01) (0) (S, 01)
(IS, 02) (0) (L, 03)
(IS, 08) (0) (L, 04)
(IS, 05) (0) (S, 02)
(DL, 01) (C, 01)
(DL, 01) (C, 01)
(DL, 01) (C, 01)
(IS, 00)
(AD, 01)
Conclusion:
Thus we have implemented the one pass-I of II pass Assembler using C
language.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
5
Software Laboratory
Assignment No. 2
Title of Assignment:
Implement pass-II of a two-pass assembler for 8 bit
microprocessor/pseudo-machine. The output of assignment-1
(intermediate file and symbol table) should be input for this assignment.
Problem Statement(s) :
Implement one pass-II of TWO Pass assembler with hypothetical Instruction
set using C language. Instruction set should include all types of assembly
language statements such as Imperative, Declarative and Assembler Directive.
While designing stress should be given on
a) How efficiently Mnemonic opcode table could be implemented so
as to enable faster retrieval on op-code.
b) Implementation of symbol table for faster retrieval.
( Concepts in DSF should be applied while design)
Relevant Theory:
1 .Explain what is meant by pass of an assembler.
2. Explain the need for two pass assembler.
3. Explain terms such as Forward Reference and backward reference.
4. Explain various types of errors that are handled in two different passes.
5. Explain the need of Intermediate Code generation and the variants used.
6. State various tables used and their significance in the design of two pass
Assembler
Implementation Logic :
Pass II Algorithm
It has been assumed that the target code is to be assembled in the named
code_area.
Loc_cntr:=0;
2. While next statement is not an END statement
(a) Clear machine_code_buffer;
b) If an LTORG statement
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
6
Software Laboratory
Implementation Logic :
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
7
Software Laboratory
Pass II: -
Synthesize the target code by processing the intermediate code
generated during
Testing:
Testing:
SAMPLE PROGRAM Input
START 200
READ A
READ B
MOVER AREG, ='5'
MOVER AREG, A
ADD AREG, B
SUB AREG, ='6'
MOVEM AREG, C
PRINT C
LTORG
MOVER AREG, ='15'
MOVER AREG, A
ADD AREG, B
SUB AREG, ='16'
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
8
Software Laboratory
9
Software Laboratory
PASS II OUTPUT
Target Code
200) + 09 0 216
201) + 09 0 217
202) + 04 0 208
203) + 04 0 216
204) + 01 0 217
205) + 02 0 209
206) + 05 0 218
207) + 10 0 218
208) + 00 0 005
209) + 00 0 006
210) + 04 0 220
211) + 04 0 216
212) + 01 0 217
213) + 02 0 221
214) + 08 0 222
215) + 05 0 218
216)
217)
218)
219) + 00 0 000
220) + 00 0 015
221) + 00 0 016
222) + 00 0 026
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
10
Software Laboratory
Conclusion:
Thus we have implemented the one pass-II of II pass Assembler using C
language.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
11
Software Laboratory
Assignment No. 3
Title of Assignment:
Design suitable data structures and implement pass-I of a two-pass macro-
processor.
Problem Statement(s) :
Implement the program for pass-I of a two pass macro-processor using c
language.
Relevant Theory:
1. Explain what is meant by pass of macro-processor.
6. State various tables used and their significance in the design of two
pass macro-processor.
12
Software Laboratory
It consists of
1. Macro Prototype Statement - this declares the name of macro & types
of parameters.
2. Model statement - It is statement from which assembly language
statement is generated during macro expansion.
3. Preprocessor Statement - It is used to perform auxiliary function
during macro expansion.
1. Use of AIF & AGO allows us alter the flow of control during expansion.
2. Loops can be implemented using expansion time variables.
Implementation Logic :
1. Definition processing - Scan all macro definitions and for each macro
definition enter the macro name in macro name table (MNT). Store
entire macro definition in macro definition table (MDT) and add
auxiliary information in MNT such as no of positional parameters
(#PP) no of key word parameters (#KP), macro definition table position
(MDTP) etc.
2. Macro expansion - Examine all statement in assembly source
program to detect the macro calls. For each macro call locate the
macro in MNT, retrieve MDTP, establish the correspondence between
formal & actual parameters and expand the macro.
13
Software Laboratory
Algorithm/Pseudo code:
Before processing any definition initialize KPDTAB_ptr, MDT_ptr to 0 and
MNT_ptr to -1. These table pointers are common to all macro definitions. For
each macro definition perform the following steps.
A one-pass macro processor that alternate between macro definition and macro
expansion in a recursive way is able to handle recursive macro definition.
Because of
the one-pass structure, the definition of a macro must appear in the source
program before any statements that invoke that macro.
Algorithm:
begin {macro processor}
EXPANDING : = FALSE
while OPCODE ≠ ‘END’ do
begin
GETLINE
PROCESSLINE
end {while}
end {macro processor}
procedure PROCESSLINE
begin
search NAMTAB for OPCODE
if found then
EXPAND
else if OPCODE = ‘MACRO’ then
DEFINE
else write source line to expanded file
end {PROCESSLINE}
Algorithm:
procedure EXPAND
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
14
Software Laboratory
begin
EXPANDING : = TRUE
get first line of macro definition {prototype} from DEFTAB
set up arguments from macro invocation in ARGTAB
write macro invocation to expanded file as a comment
while not end of macro definition do
begin
GETLINE
PROCESSLINE
end {while}
EXPANDING : = FALSE
end {EXPAND}
procedure GETLINE
begin
if EXPANDING then
begin get next line of macro definition
from DEFTAB
substitute arguments from ARGTAB for positional
notation
end {if}
else
read next line from input file
end {GETLINE}
15
Software Laboratory
16
Software Laboratory
Testing:
The assembly language program with macro definitions & macro calls
MACRO
MAC1
MOVER AREG, M
ADD BREG, M
MOVEM CREG, M
MEND
MACRO
EVAL &X,&Y,&Z
MOVER AREG, &X
SUB AREG, &Y
ADD AREG, &Z
MOVER AREG, &Z
MEND
MACRO
CALC &X,&Y,&OP=MULT,&LAB=
&LAB MOVER AREG, &X
&OP AREG, &Y
MOVEM AREG, &X
MEND
START
MOVEM AREG, B
EVAL A, B, C
ADD AREG, N
MOVEM AREG, N
CALC P, Q, LAB=LOOP:
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
17
Software Laboratory
MOVEM AREG, N
MAC1
CALC P,Q,OP=DIV, LAB=NEXT
M DS 1
A DS 5
B DS 1
C DS 1
N DS 1
P DS 1
Q DS 1
END
Sample output: -
Macro name Table
18
Software Laboratory
START
MOVEM AREG, B
+ MOVER AREG, A // expanded code of EVAL
+SUB AREG, B
+ADD AREG, C
+MOVER AREG, C
ADD AREG, N
MOVEM AREG, N
+ LOOP MOVER AREG, P // expanded code for CALC
+MULT AREG, Q
+MOVEM AREG, P
MOVEM AREG,N
+MOVER AREG, M // expanded code for MAC1
+ADD BREG, M
+MOVEM CREG, M
+ NEXT MOVER AREG, P // expanded code for CALC
+DIV AREG, Q
+MOVEM AREG, P
A DS 5
B DS 1
C DS 1
N DS 1
P DS 1
Q DS 1
END
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
19
Software Laboratory
Conclusion:
Thus we have implemented pass-I of two pass Macro processor using C
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
20
Software Laboratory
Assignment No. 4
Title of Assignment :
Design suitable data structures and implement pass-II of a two-pass
macro-processor.
Problem Statement:
Write a program in C for a pass-II of two pass macro processor for
implementation of Macro Processor.
Following cases to be considered
a) Macro without any parameters
b) Macro with Positional Parameters
c) Macro with Key word parameters
d) Macro with positional and keyword parameters.
( Conditional expansion , nested macro implementation not
expected)
It consists of
1. Macro Prototype Statement - this declares the name of macro &
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
21
Software Laboratory
types of parameters
2. Model statement - It is statement from which assembly language
statement is generated during macro expansion.
3. Preprocessor Statement - It is used to perform auxiliary function
during macro expansion.
1. Use of AIF & AGO allows us alter the flow of control during
expansion.
2. Loops can be implemented using expansion time variables.
Testing:
The assembly language program with macro definitions & macro calls
MACRO
MAC1
MOVER AREG, M
ADD BREG, M
MOVEM CREG, M
MEND
MACRO
EVAL &X,&Y,&Z
MOVER AREG, &X
SUB AREG, &Y
ADD AREG, &Z
MOVER AREG, &Z
MEND
MACRO
CALC &X,&Y,&OP=MULT,&LAB=
&LAB MOVER AREG, &X
&OP AREG, &Y
MOVEM AREG, &X
MEND
START
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
22
Software Laboratory
MOVEM AREG, B
EVAL A, B, C
ADD AREG, N
MOVEM AREG, N
CALC P, Q, LAB=LOOP:
MOVEM AREG, N
MAC1
CALC P,Q,OP=DIV, LAB=NEXT
M DS 1
A DS 5
B DS 1
C DS 1
N DS 1
P DS 1
Q DS 1
END
Sample output: -
Macro name Table
23
Software Laboratory
START
MOVEM AREG, B
+ MOVER AREG, A // expanded code of EVAL
+SUB AREG, B
+ADD AREG, C
+MOVER AREG, C
ADD AREG, N
MOVEM AREG, N
+ LOOP MOVER AREG, P // expanded code for CALC
+MULT AREG, Q
+MOVEM AREG, P
MOVEM AREG,N
+MOVER AREG, M // expanded code for MAC1
+ADD BREG, M
+MOVEM CREG, M
+ NEXT MOVER AREG, P // expanded code for CALC
+DIV AREG, Q
+MOVEM AREG, P
A DS 5
B DS 1
C DS 1
N DS 1
P DS 1
Q DS 1
END
24
Software Laboratory
Conclusion:
Thus we have implemented pass-II of two pass Macro processor using C.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
25
Software Laboratory
Assignment No. 5
Title of Assignment :
DLL Creation
Problem Statement:
Write a program to create Dynamic Link Library for any mathematical
operation and write an application program to test it
Relevant Theory / Literature Survey:
1. Explain the need of dll.
2. Explain the console application
3.Explain the various library which is need for creating the dll
4.Explain the method of declaration and definition of method
Design Analysis/ Implementation Logic:
Creating a dll
2. create a console application in Visual C++ which links with the dll just
created and uses the function stored in the dll
3. In the New window that appears choose win-32 Dynamic Link library,
give a valid project name for. E.g. say calc_dll and choose a valid project
location if required.
5. Then click ok. Visual C++ editor opens up the project related basic
files.
6. From the left bottom window choose file view instead of class view .
7. Double click calc_dll.cpp file to open it in the editor from the le7t side
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
26
Software Laboratory
Window.
10. Now declare the function which will be contained in the dll. Here we
will just define a divide function which will accept two numbers and
return their division.
Syntax :
extern “C” __declspec(dllexport)double divide(double,double);
This syntax tells the compiler that this function will be exported with its
formal parameters and the return type.
For e.g.
double divide(double x, double y)
{
if (y==0)
{
Throw invalid argument (“Divide by zero error !!”);
}
else
{
return x/y;
}
}
13. Now click on the Build icon in standard toolbar or press F7 to build
the dll.
27
Software Laboratory
4. Click OK. In the next window when asked to specify the type of console
application as a “simple hello world” application.
5. Click OK. The Visual C++ editor opens up basic required files.
#include<iostream>
and the default namespace as :
using namespace std;
10. Declare the function which we will be using by linking to the dll we
just created.
11. Remember that syntax (formal parameters and return type) of the
function declared here and in the dll must be same.
14. Here by making a call to the divide function, the division of the two
numbers is done and the result is stored in the result variable.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
28
Software Laboratory
15. Now as we have not defined the divide () function in this program
rather we are using by linking to a dll .
16. For linking our “calc” program with the dll “calc_dll” we will make use
of the library file created with our “calc_dll”.
18. in this folder go to the “debug “ folder and copy two files “calc_dll.dll”
and “calc_dll.lib” .
19. paste these two files in our current project directory ‘s debug folder
which path could be like :
20. Note that by now the “debug “ folder in the “calc” project directory
should contain our two required files “calc_dll.dll” and “calc_dll.lib”.
21. For linking our program “calc” with the calc_dll we need to include the
calc_dll.lib file into our current project.
23. Select the file type as all file types from the file type drop down
window.
24. Browse to debug folder of our current project and select the
“calc_dll.lib”.
27. Now run the application by clicking Run button or press CTRL+F5.
Conclusion:
Thus we have studied dll creation using console application
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
29
Software Laboratory
Assignment No. 6
Title of Assignment :
Deadlock avoidance using Banker's Algorithm.
Problem Statement(s) :
Implement Banker Algorithm for Deadlock avoidance.
Relevant Theory / Literature Survey:
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
30
Software Laboratory
Testing:
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
31
Software Laboratory
ABCD
3112
ABCD
P1 1 2 2 1
P2 1 0 3 3
P3 1 1 1 0
ABCD
P1 3 3 2 2
P2 1 2 3 4
P3 1 1 5 0
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
32
Software Laboratory
Assignment No. 7
Title of Assignment :
Simulation of following CPU scheduling algorithms
Problem Statement(s) :
Implement following programs to simulate following CPU scheduling algorithms
a. FCFS
b. SJF (preemptive and non-preemptive)
c. Priority Scheduling (preemptive and non-preemptive)
d. Round Robin Scheduling
Relevant Theory:
Uniprocessor Scheduling
Types of Scheduling
Non-preemptive Scheduling
Preemptive Scheduling
Algorithm
Advantages
Disadvantages
33
Software Laboratory
An array/linked list of such a structure will store the set of processes for which
CPU scheduling can be applied.
A queue or priority queue using array / linked list has to be appropriately
maintained to implement the algorithms.
Testing:
For the given data [Consider relevant of data depending on the scheduling
algorithm]
Process Arrival Time Burst Time Priority
A 0 3 2
B 2 6 3
C 4 4 4
D 6 5 5
E 8 2 1
Apply the scheduling algorithms like FCFS, (Both Preemptive & Non
Preemptive) SJF, Priority, Round Robin (quantum = 2 ms)
Conclusion:
Thus we have learnt and implemented following programs to simulate the CPU
scheduling algorithms like
a. FCFS
b. SJF (preemptive and non-preemptive)
c. Priority Scheduling (preemptive and non-preemptive)
d. Round Robin Scheduling
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
34
Software Laboratory
Assignment 8
Title of Assignment :
Simulation of Page replacement algorithms ( FIFO, LRU, Optimal)
Problem Statement:
Implement Page replacement algorithms ( FIFO, LRU, Optimal)
Relevant Theory / Literature Survey:
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
35
Software Laboratory
1. LRU policy replaces the page in memory that has not been
referenced for the longest time.
2. The LRU algorithm performs better than FIFO. The LRU algorithm
belongs to a larger class of stack replacement algorithms. When
more real memory is made available to the executing program,
stack algorithm therefore do not suffer from Belady’s anomaly.
Optimal Page Replacement:
2. Replace the page that will be referenced furthest in the future or not at
all.
Testing:
Reference String: 4 3 2 1 4 3 5 4 3 2 1 5
No of Frames: 3 or 4
Conclusion:
Hence we have implemented the page replacement algorithms.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
36
Software Laboratory
Assignment 9
Title of Assignment :
Multithreading Concept
Problem Statement:
Implement Producer-Consumer using multi-threading concept.
Relevant Theory / Literature Survey:
#DEFINE N 50
typedef int semaphore;
semaphore mutex=1;
semaphore empty=N; semaphore full=0;
void producer(void)
{
int item;
while(TRUE)
{
item=producer_item( )
down(&empty);
down(&mutex);
insert_item(item);
up(&mutex);
up(&full);
}
}
void consumer(void)
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
37
Software Laboratory
int item;
while(TRUE)
{
down(&full);
down(&mutex);
item=remove_item( );
up(&mutex);
up(&empty);
consume_item(item);
}
}
Conclusion:
Inter-process Communication for Producer-Consumer problem in UNIX
(Pipes or Shared Memory) has been implemented.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
38
Software Laboratory
Assignment No. 10
Title of Assignment :
Multithreading Concept.
Problem Statement:
Implement Reader-Writer problem using multi-threading concept.
Relevant Theory / Literature Survey:
39
Software Laboratory
while(TRUE)
{
think_up_data( );
down(&db);
write_data_base( );
up(&db);
}
}
Conclusion:
Implement Mutual Exclusion and Synchronization of threads using
POSIX Semaphores has been implemented.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
40
Software Laboratory
Assignment No. 11
Title of Assignment :
Linux Kernel Compilation
Problem Statement:
Linux Kernel Compilation Download a raw Linux Kernel(www.kernel.org) compile
it and boot the machine through newly compiled
Relevant Theory / Literature Survey:
Steps of Compilation
Visit http://kernel.org/ and download the latest source code. File name
would be linux-x.y.z.tar.bz2, where x.y.z is actual version number. For
example file inux-2.6.25.tar.bz2 represents 2.6.25 kernel version.
$ cd /tmp
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2
Before you configure kernel make sure you have development tools (gcc
compilers and related tools) are installed on your system. If gcc compiler
and tools are not installed then use apt-get command under Debian
Linux to install development tools.
# apt-get install gcc
Now you can start kernel configuration by typing any one of the
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
41
Software Laboratory
command:
You have to select different options as per your need. Each configuration
option has HELP button associated with it so select help button to get
help.
It will install three files into /boot directory as well as modification to your
kernel grub configuration file:
System.map-2.6.25
config-2.6.25
vmlinuz-2.6.25
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
42
Software Laboratory
initrd images contains device driver which needed to load rest of the
operating system later on. Not all computer requires initrd, but it is safe
to create one.
root (hd0,0)
initrd /boot/initrd.img-2.6.25
savedefault
boot
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
43
Software Laboratory
# reboot
Conclusion:
Linux Kernel Compilation has been studied.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
44
Software Laboratory
Assignment 12
Title of Assignment :
System Calls
Problem Statement:
Study UNIX system calls like ps, fork, join , exec family ,wait for process
management.
Relevant Theory / Literature Survey:
ps [-eflu]
In the following example, the user is logged on to the console, and has no
jobs running, except for his/her shell and of course the command itself.
>ps
The next example shows a user using a windowing interface (in this case,
SunView):
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
45
Software Laboratory
> ps
1342 co S 3:59 textedit -Wp 479 98 -Ws 673 764 -WP 840 0 -Wi
1343 co S 0:28 clock -Wp 497 32 -Ws 210 47 -WP 704 0 -Wi -S
1340 p0 D 1:34 cmdtool -Wp 0 0 -Ws 673 471 -WP 0 0 -Wl $<<$
CONSOLE $>>$
1438 p0 R 0:00 ps
1347 p1 S 1:38 cmdtool -Wp 0 350 -Ws 673 550 -WP 772 0 -Wi
This user has many processes running, each of them taking some CPU
time. Some of the programs running are the windowing system (sunview),
textedit (a full screen ``point-and-click" editor), a clock, a performance
meter, a C shell, two windows (cmdtool), a remote logon to node nrccsb2,
and the ps program. The first column of the output is the process id, the
second column is the control terminal (co = console, p0 = ttyp0, p1 =
ttyp1), the third column is the state of the job (I = idle process, W =
swapped out, S = sleeping, D = in disk waits, R = runnable). The next
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
46
Software Laboratory
column displays the CPU time used by the process so far, in minutes:
seconds, and finally, the last column displays the command used. fork();
SYNOPSIS
DESCRIPTION
The fork () function creates a new process. The new process (child process)
is an exact copy of the calling process (parent process) except as detailed
below.
The child process has a unique process ID.
The child process ID also does not match any active process group
ID.
The child process has a different parent process ID (that is, the
process ID of the parent process).
The child process has its own copy of the parent's file descriptors.
Each of the child's file descriptors refers to the same open file
description with the corresponding file descriptor of the parent.
The child process has its own copy of the parent's open directory
streams. Each open directory stream in the child process may share
directory stream positioning with the corresponding directory
stream of the parent.
The child process may have its own copy of the parent's message
catalogue descriptors.
The child process' values of tms_utime, tms_stime, tms_cutime and
tms_cstime are set to 0.
The time left until an alarm clock signal is reset to 0.
All semadj values are cleared.
File locks set by the parent process are not inherited by the child
process.
The set of signals pending for the child process is initialised to the
empty set.
Interval timers are reset in the child process.
If the Semaphores option is supported, any semaphores that are
open in the parent process will also be open in the child process.
If the Process Memory Locking option is supported, the child
process does not inherit any address space memory locks
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
47
Software Laboratory
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
48
Software Laboratory
join:
NAME
join - join lines of two files on a common field
SYNOPSIS
Join [OPTION]... FILE1 FILE2
DESCRIPTION
For each pair of input lines with identical join fields, write a line to
standard output. The default join field is the first, delimited by
whitespace. When FILE1 or FILE2 (not both) is -, read standard input.
-a SIDE
print unpairable lines coming from file SIDE
-e EMPTY
replace missing input fields with EMPTY
-i, --ignore-case ignore differences in case when comparing fields
-j FIELD
(obsolescent) equivalent to `-1 FIELD -2 FIELD'
-j1 FIELD
(obsolescent) equivalent to `-1 FIELD'
-j2 FIELD
(obsolescent) equivalent to `-2 FIELD'
-o FORMAT
obey FORMAT while constructing output line
-t CHAR
use CHAR as input and output field separator
-v SIDE
like -a SIDE, but suppress joined output lines
-1 FIELD
join on this FIELD of file 1
-2 FIELD
join on this FIELD of file 2
--help
display this help and exit
--version
output version information and exit
Unless -t CHAR is given, leading blanks separate fields and are ignored,
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
49
Software Laboratory
else fields are separated by CHAR. Any FIELD is a field number counted
from 1. FORMAT is one or more comma or blank separated specifications,
each being `SIDE.FIELD' or `0'. Default FORMAT outputs the join field,
the remaining fields from FILE1, the remaining fields from FILE2, all
separated by CHAR.
SEE ALSO
The full documentation for join is maintained as a Texinfo manual. If the
info and join programs are properly installed at your site, the command
exec family:
NAME
SYNOPSIS
#include <unistd.h>
int execl(const char *path, const char *arg0, ... /*, (char *)0 */);
const char *arg0, ... /*, (char *)0, char *const envp[]*/);
int execve(const char *path, char *const argv[], char *const envp[]);
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
50
Software Laboratory
int execlp(const char *file, const char *arg0, ... /*, (char *)0 */);
DESCRIPTION
The exec functions replace the current process image with a new process
image. The new image is constructed from a regular, executable file called
the new process image file. There is no return from a successful exec,
because the calling process image is overlaid by the new process image.
The arguments specified by a program with one of the exec functions are
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
51
Software Laboratory
The argument path points to a pathname that identifies the new process
image file.
The argument file is used to construct a pathname that identifies the new
process image file. If the file argument contains a slash character, the file
argument is used as the pathname for this file. Otherwise, the path prefix
for this file is obtained by a search of the directories passed as the
environment variable (see XBD specification, Environment Variables ). If
this environment variable is not present, the results of the search are
implementation-dependent.
If the process image file is not a valid executable object, execlp() and
execvp() use the contents of that file as standard input to a command
interpreter conforming to system(). In this case, the command interpreter
becomes the new process image.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
52
Software Laboratory
For those forms not containing an envp pointer (.Fn execl , execv(),
execlp() and execvp()), the environment for the new process image is taken
from the external variable environ in the calling process.
The number of bytes available for the new process' combined argument
and environment lists is {ARG_MAX}. It is implementation-dependent
whether null terminators, pointers, and/or any alignment bytes are
included in this total.
File descriptors open in the calling process image remain open in the new
process image, except for those whose close-on-exec flag FD_CLOEXEC is
set. For those file descriptors that remain open, all attributes of the open
file description, including file locks remain unchanged.
Directory streams open in the calling process image are closed in the new
process image.
setlocale(LC_ALL, "C")
is executed at startup.
Signals set to the default action (SIG_DFL) in the calling process image
are set to the default action in the new process image. Signals set to be
ignored (SIG_IGN) by the calling process image are set to be ignored by
the new process image. Signals set to be caught by the calling process
image are set to the default action in the new process image (see
<signal.h>). After a successful call to any of the exec functions, alternate
signal stacks are not preserved and the SA_ONSTACK flag is cleared for
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
53
Software Laboratory
all signals.
If the ST_NOSUID bit is set for the file system containing the new process
image file, then the effective user ID, effective group ID, saved set-user-ID
and saved set-group-ID are unchanged in the new process image.
Otherwise, if the set-user-ID mode bit of the new process image file is set,
the effective user ID of the new process image is set to the user ID of the
new process image file. Similarly, if the set-group-ID mode bit of the new
process image file is set, the effective group ID of the new process image is
set to the group ID of the new process image file. The real user ID, real
group ID, and supplementary group IDs of the new process image remain
the same as those of the calling process image. The effective user ID and
effective group ID of the new process image are saved (as the saved set-
user-ID and the saved set-group-ID for use by setuid().
Any shared memory segments attached to the calling process image will
not be attached to the new process image.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
54
Software Laboratory
The new process also inherits at least the following attributes from the
calling process image:
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
55
Software Laboratory
process group ID
session membership
real user ID
real group ID
supplementary group IDs
time left until an alarm clock signal (see alarm())
current working directory
root directory
file mode creation mask (see umask())
file size limit (see ulimit())
process signal mask (see sigprocmask())
pending signal (see sigpending())
tms_utime, tms_stime, tms_cutime, and tms_cstime (see times())
resource limits
controlling terminal
interval timers
All other process attributes defined in this document will be the same in
the new and old process images. The inheritance of process attributes not
defined by this specification is implementation-dependent.
A call to any exec function from a process with more than one thread
results in all threads being terminated and the new executable image
being loaded and executed. No destructor functions will be called.
Upon successful completion, the exec functions mark for update the
st_atime field of the file. If an exec function failed but was able to locate
the process image file, whether the st_atime field is marked for update is
unspecified. Should the exec function succeed, the process image file is
considered to have been opened with open(). The corresponding close() is
considered to occur at a time after this open, but before process
termination or successful completion of a subsequent call to one of the
exec functions. The argv[] and envp[] arrays of pointers and the strings to
which those arrays point will not be modified by a call to one of the exec
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
56
Software Laboratory
The saved resource limits in the new process image are set to be a copy of
the process's corresponding hard and soft limits.
RETURN VALUE
If one of the exec functions returns to the calling process image, an error
has occurred; the return value is -1, and err no is set to indicate the error.
Wait:
NAME
SYNOPSIS
#include <sys/wait.h>
DESCRIPTION
The wait() function shall suspend execution of the calling thread until
status information for one of the terminated child processes of the calling
process is available, or until delivery of a signal whose action is either to
execute a signal-catching function or to terminate the process. If more
than one thread is suspended in wait () or waitpid() awaiting termination
of the same process, exactly one thread shall return the process status at
the time of the target process termination. If status information is
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
57
Software Laboratory
The pid argument specifies a set of child processes for which status is
requested. The waitpid() function shall only return the status of a child
process from this set:
If pid is less than (pid_t)-1, status is requested for any child process
whose process group ID is equal to the absolute value of pid.
WCONTINUED
The waitpid() function shall report the status of any continued child
process specified by pid whose status has not been reported since it
continued from a job control stop.
WNOHANG
The waitpid() function shall not suspend execution of the calling
thread if status is not immediately available for one of the child
processes specified by pid.
WUNTRACED
The status of any child processes specified by pid that are stopped,
and whose status has not yet been reported since they stopped,
shall also be reported to the requesting process.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
58
Software Laboratory
of the children of the process containing the calling thread terminate, and
wait() and waitpid() shall fail and set errno to [ECHILD].
3. The process was terminated because the last thread in the process
terminated.
WIFEXITED(stat_val)
Evaluates to a non-zero value if status was returned for a child
process that terminated normally.
WEXITSTATUS(stat_val)
If the value of WIFEXITED (stat_val) is non-zero, this macro
evaluates to the low-order 8 bits of the status argument that the
child process passed to _exit() or exit(), or the value the child
process returned from main().
WIFSIGNALED(stat_val)
Evaluates to a non-zero value if status was returned for a child
process that terminated due to the receipt of a signal that was not
caught (see <signal.h>).
WTERMSIG(stat_val)
If the value of WIFSIGNALED (stat_val) is non-zero, this macro
evaluates to the number of the signal that caused the termination
of the child process.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
59
Software Laboratory
WIFSTOPPED(stat_val)
Evaluates to a non-zero value if status was returned for a child
process that is currently stopped.
WSTOPSIG(stat_val)
If the value of WIFSTOPPED (stat_val) is non-zero, this macro
evaluates to the number of the signal that caused the child process
to stop.
WIFCONTINUED (stat_val)
Evaluates to a non-zero value if status was returned for a child
process that has continued from a job control stop. It is unspecified
whether the status value returned by calls to wait() or waitpid() for
processes created by posix_spawn() or posix_spawnp() can indicate a
WIFSTOPPED(stat_val) before subsequent calls to wait() or waitpid()
indicate WIFEXITED(stat_val) as the result of an error detected before the
new process image starts executing.
It is unspecified whether the status value returned by calls to wait() or
waitpid() for processes created by posix_spawn() or posix_spawnp() can
indicate a WIFSIGNALED(stat_val) if a signal is sent to the parent's
process group after posix_spawn() or posix_spawnp() is called.
60
Software Laboratory
that did not specify the WUNTRACED flag and specified the
WCONTINUED flag, or by a call to the wait() function, exactly one of the
macros WIFEXITED(*stat_loc), WIFSIGNALED(*stat_loc), and
WIFCONTINUED(*stat_loc) shall evaluate to a non-zero value.
If a parent process terminates without waiting for all of its child processes
to terminate, the remaining child processes shall be assigned a new
parent process ID corresponding to an implementation-defined system
process.
RETURN VALUE
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
61
Software Laboratory
Conclusion:
Thus system call has been studied.
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
62
Software Laboratory
Third Year
Computer Engineering
G.H.R.C.E.M, Wagholi
63