Operating system Experiment instruction book (full version) __ Operating system Experiment Instruction book

Source: Internet
Author: User
Tags chmod create directory mkdir rand file permissions

Operating System Experiment Instruction book

Computer College of Yantai University

Operating System Course Group

2008-9-20

the first part of the operating system on the computer guidance

Linux Operating system environment:
RedHat Enterprise Linux ES Release 3 (Taroon Update 1) (2.4.21-9.el)

Red Flag Linux Release 4.0 (Hot) (2.4)

log on to the system

Common Command Exercises :

Register with Root account (Superuser), password is computer (note case). Registration successfully appears # (Superuser system prompt, the normal user's system prompt is $).

1. Logout (Exit) System: Logout or exit

3. Practice using Command LS (note that Linux commands are case-sensitive.) )

Use LS to view the contents of the current directory; Use LS to view the contents of the specified directory, such as/directory,/etc directory

Use Ls–all to view the contents of the current directory; Use dir to view the contents of the current directory

4. Change the current directory with a CD

CD .. Go back to the top directory; CD/back to the root directory

5. PWD Show current path

6. Create directory MkDir

mkdir directory name; mkdir/home/s2001/newdir

7. Delete directory: rmdir;

8. Copy file CP: such as CP filename 1 filename 2

9. To move a file or directory: MV

10. Delete File rm

11. Display the contents of the file: more (pagination display);

12. display file: Cat filename Creation file: cat > FileName, ctrl+d end input

edit a file with editor VI

1. After entering the Linux text mode, type VI filename.c at the command line and enter. Here are some simple explanations: First VI command is to open VI editor. The filename.c in the back is the name of the C file that the user is about to edit, noting that the extension name is. C; Of course, the VI editor is very powerful, you can use it to edit other formats of the file, such as assembly file, its extended name is. s; You can also open a new unnamed file directly with VI, and then name it when you save it, but it's not very Convenient.

2. The most basic command I: When entering the newly opened file, can not write information, then click on the keyboard I (insert), the meaning of insertion, you can enter the editing mode. As shown in the following illustration:

3. A and I are the same usage

4. When the file is edited, you need to save the exit, you need to go through the following steps: 1 Click the ESC key on the keyboard; 2 Type a colon (:), immediately following the colon is wq (meaning save and exit). If you do not want to save the exit, type Q after you type the colon in the second step. (without w, machine tail to save). As shown in the following illustration:

5. Exit the VI editor after editing mode, to the program just written to compile. The compiled command is: gcc filename.c [-o outputfilename.out], where GCC is the compiler for C. Parameters: Filename.c is the name of the source file to compile, OutputFileName represents the output file name, and the brackets indicate that the contents inside the parentheses can or will not be entered (the brackets themselves are no longer in the command line). If you do not enter Outputfilename.out, the default output file is a.out.

6. The final step is to run the program in the following ways:./outputfilename.out

 

adding new users, modifying file properties

1. Add new user (under Root, answer by default)

AddUser user name, such as AddUser s2001; Log on to the system with a new user

2. Modify user password passwd user name

3. Control file Properties

Using Ls–l to view file properties

Change the user's ownership: Chown Username file name

Change file permissions: chmod g+w filename; chmod o-r filename

or digitally modified: such as chmod 644 filename; chmod 755 filename

U (user), G (group), O (other others); W Write access, R read access, x Execute permissions

4. To view Help for related commands: Man command name

5. Displays registered user information in the current system: WHO

6. Displays the currently registered user information: WhoAmI

TIP:

Attribute display format for UNIX file directories:

such as:-rw-rw-rw-1 Steve users 138 APR 5 19:34 Readme

DRWXRWXRWX 3 Steve users Apr 5 19:43 Dir1

Three types of permissions: Owner Group Others

The second part of operating system experiment

Experiment 1 Linux Basic Environment

1. Experimental purposes

(1) familiar with the basic operation of Linux, learn to use a variety of shell commands to operate Linux, there is a perceptual knowledge of Linux.

(2) Learn to use VI Editor to edit a simple C language program, and can be compiled and debugged.

2, the experimental preparation content

(1) See the relevant Linux operating system installation manual, familiar with the basic Linux installation and configuration;

(2) Refer to the relevant Linux command reference manual, familiar with the operation commands under Linux.

3. Experimental content

(1) as root user login, and use "ls", "Cat" "CD" and other commands to achieve basic file operation and observe the characteristics of Linux file system;

(2) write a C program using the VI Editor, compile and link with the GCC command, and use a.out to output the results.

4. Thinking

(1) What are the characteristics of the Linux system in user login and operation interface and file system.

Experiment 2 Process Management

1. Experimental purposes

(1) Deepen the understanding of the concept of processes and clarify the differences between processes and procedures.

(2) Further understanding the essence of concurrent execution.

(3) Analyzing the Process competition resource phenomenon, learning how to solve the process of mutual exclusion.

(4) Understand the basic principles of process communication in Linux systems.

2, the experimental preparation content

(1) Read Linux sched.h source files, deepen understanding of the concept of process management.

(2) Read the Linux fork.c source files and analyze the process creation process.

3. Experimental content

(1) Process creation

Write a source program that causes the system to call Fork () to create two child processes, and when the program runs, there is a parent process and two child process activities in the system. Let each process display a character on the screen: the parent process displays the character "a", and the child processes display the character "B" and the character "C", respectively. Try to observe the display on the record screen and analyze the reason.

(2) control of the process

Modify a program that has been written to output one character per process to each process output sentence, the appearance of the screen during the Watch program execution, and analyze the cause.

If you use the call LOCKF () in your program to lock each child process, you can achieve mutual exclusion between processes, and observe and analyze the phenomena that occur.

(3) ① write a program to make its actual process soft interrupt communication.

Requirements: Use system call fork () to create two child processes, and then use System call signal () to let the parent process catch the interrupt signal (that is, press the DEL key) on the keyboard, and when the interrupt signal is captured, the parent process signals to two sub processes with system call Kill (). The child process terminates after it captures the signal, outputting the following information separately:

Child Processll was killed by parent!

Child PROCESSL2 was killed by parent!

After the parent process waits for two child processes to terminate, the output is terminated after the following information

Parent Process is killed!

② adds statements SIGNAL (SIGNAL, sig-ign) and SIGNAL (Sigquit, sig-ign) in the above program, observes the execution results, and analyzes the cause.

(4) Pipeline communication of the process

Compile a program to realize the management communication of the process.

Use system call pipe () to establish a pipe line; two subprocess P1 and P2 write a sentence to the pipe respectively:

Child 1 is sending a message!

Child 2 is sending a message!

The parent process, however, reads information from the pipeline from the two child processes and displays them on the screen.

The parent process is required to receive a message from the subprocess P1 before receiving the message from the subprocess P2.

4. Thinking

(1) How the system creates the process.

(2) What to do when the executable file is loaded.

(3) Where the portal is when the new creation process is first invoked.

(4) What is the characteristic of process communication.

Experiment 3 Inter-process communication

1. Experimental purposes

The process communication mechanism (IPC) of Linux systems allows the exchange of data in large quantities between any processes. The purpose of this experiment is to understand and familiarize with the message communication mechanism and information mechanism supported by Linux.

2, the experimental preparation content

Read the Linux system msg.c, SEM.C and shm.c source files, familiar with the Linux three mechanisms.

3. Experimental content

(1) The creation, sending and receiving of messages.

① uses system invoke Msgget (), msgsnd (), Msgrev (), and Msgctl () to compile a 1k-length message sending and receiving program.

② observes the above program, and explains how the control Message Queuing system call MSGCTL () plays a role here.

(2) Create, attach, and segment the shared storage area.

Use the system call Shmget (), Shmat (), SGMDT (), Shmctl (), and compile a program that is the same as the one described above.

(3) Compare the time of data transmission in the above (1) and (2) message communication mechanisms.

Experiment 4 Storage Management

1. Experimental purposes

One of the main functions of storage management is to allocate space reasonably. Request-page management is a common virtual storage management technology.

The purpose of this experiment is to design the page replacement algorithm in the page storage management, to understand the technical characteristics of the virtual storage technology, and to master the page replacement algorithm of the request page storage management.

2. Experimental content

(1) Generate a sequence of instructions by random number, a total of 320 instructions. The address of the directive is generated according to the following principles:

The ①50% instructions are executed sequentially;

The ②50% instruction is evenly distributed in the front address part;

The ③50% instructions are evenly distributed in the back address section.

The specific implementation methods are:

The ① selects a beginning m between the instructions in [0,319];

② Order executes an instruction, namely the execution address is m+1 instruction;

③ in the former address [0,m+1] randomly selects an instruction and executes, the instruction address is m′;

The ④ order executes an instruction whose address is m′+ 1;

⑤ in the post address [m′+ 2,319] randomly selects an instruction and executes;

⑥ repeats the above steps ①-⑤ until 320 instructions are executed.

(2) transforming the instruction sequence into a page address stream

Setting: ① page size is 1k;

② user memory capacity is 4 pages to 32 pages;

③ user Virtual storage capacity of 32k.

In the user's virtual deposit, 10 instructions per k are placed in the virtual deposit address, that is, 320 instructions stored in the virtual deposit mode is:

No. 0-9th instruction is page No. 0 (corresponding to the virtual deposit address is [0,9]);

10th-19th instruction is the first page (corresponding to the virtual deposit address is [10,19]);

... ...

The No. 310 ~ No. 319 instruction is page 31st (the corresponding virtual address is [310,319]).

In the above way, the user instruction can compose 32 pages.

(3) Calculation and output of the following algorithms in different memory capacity of the hit rate.

① First Out algorithm (FIFO);

② Least Recently used algorithm (LRR);

③ Best elimination Algorithm (OPT) first elimination of the most common page address;

④ Minimum access page algorithm (LFR);

⑤ recently the least frequently used algorithm (NUR).

Where ③ and ④ are selected content.

Hit =1-page failure times/page address flow length

In this experiment, the page address flow length is 320, and the page expiration times are the number of times the page is not in memory for each time the instruction is accessed.

3, random number generation methods, Linux or UNIX systems provide functions strand () and Rand (), respectively, to initialize and generate random numbers. For example:

Srand ();

Statement to initialize a random number;

A[0]=10*rand ()/65535*319+1;

A[1]=10*rand ()/65535*a[0];

Statements can be used to produce random numbers in a[0] and a[1].

Experiment 5 File system design

1. Experimental purposes

Through a simple multi-user file system design, deepen understanding of file system internal functions and internal implementation.

2. Experimental content

Design a simple two-level file system for the Linux system. The following points are required:

(1) The following commands may be achieved (at least 4);

Login User Login

Dir Column file directory

Create creates a file

Delete Deletes files

Open File

Close File

Read reading files

Write writing files

(2) Column directory to list the file name, physical address, Protection code and file length;

(3) The source file can be read and write protected.

3. Experimental Tips

(1) First of all, we should determine the data structure of the file system: Home directory, subdirectories and active files. The home directory and subdirectories are stored as files on the disk, making it easy to find and modify.

(2) The files created by the user can be stored on disk by number. such as File0,file1,file2 ... and is registered in the directory by number as the physical address.

Experiment 6 Processor scheduling

first, the content of the experiment

Select a scheduling algorithm to implement the processor scheduling.

ii. purpose of the experiment

In a system designed by a multi-channel program, there are often several processes in the ready state at the same time. When the number of ready processes is greater than the number of processors, you must follow some policy to determine which processes are taking precedence over the processor. This experiment simulates the processor scheduling in the case of single processor, which helps students to better understand the work of processor scheduling.

third, the experiment topic

This experiment has two questions, the student may choose one of the questions to do the experiment.

The first problem: design a scheduling algorithm to implement the processor scheduling program.

[Hint]:

(1) Assume that the system has five processes, each process with a Process control block PCB to represent the Process Control block format:

Process Name

Pointer

Require run time

Priority number

State

Where the process name-the identity of the process-assumes that the process name of the five processes is p1,p2,p3,p4,p5.

Pointer--The number of five processes connected to the queue by the size of the priority, pointing to the first address of the process Control block for the next process, and the pointer to "0" in the last process.

Requires run time--the number of unit times that the process needs to run.

Priority-gives priority to the process, which always selects the process with a large number of priorities to execute first.

State--You can assume two states, a ready state, and an end state. The initial state of the five processes is "ready," which is indicated by "R", and when a process is finished, its state is "end" and "E" is used.

(2) arbitrarily determine its "priority" and "required uptime" for each process before running the processor scheduler you have designed.

(3) In order to facilitate the scheduling, the five processes in the given priority number from large to small queues. A unit is used to indicate the first process of a team, with pointers indicating the connection of the queue. Cases:

Team Head logo

K2

K1

P1

K2

P2

K3

P3

K4

P4

K5

P5

0

K4

K5

K3

K1

2

3

1

2

4

1

5

3

4

2

R

R

R

R

R

PCB1

PCB2

PCB3

PCB4

PCB5

(4) Processor scheduling always runs the first process of the selection team. By dynamically changing the priority number, the process is reduced by "1" each time a priority is run. Since this experiment is a simulation of processor scheduling, the selected process is not actually started to run, but rather executes:

Priority number-1

Required run time-1

To simulate a run of a process.

Note that in a real system, when a process is selected to run, the process must be restored to its site, allowing it to occupy the processor until a wait event or run is completed. This eliminates the work here.

(5) After the process runs once, if required to run the time ¹0, then it will be added to the queue (by the number of priority to insert, and set the team first sign); if the run time = 0 is required, the state is modified to "end" (E), and the queue is exited.

(6) If the process queue in the "Ready" state is not empty, repeat the steps above (4) and (5) until all processes become "end" states.

(7) There should be a display or print statement in the program being designed to display or print the process name of each selected process and the change in the process queue once it is run.

(8) arbitrarily determine a set of "priority number" and "required run time" for five processes, start the processor scheduler designed, display or print the process name of successive selected processes and process control block dynamic change process.

the second question: Design a time slice rotation method to implement the processor scheduling program.

[Hint]:

(1) Assuming that the system has five processes, each process is represented by a Process control block PCB. The format of the Process Control block is:

Process Name

Pointer

Require run time

Elapsed time

State

Where the process name-the identity of the process-assumes that the process name of the five processes is q1,q2,q3,q4,q5.

Pointers-The process is sequentially queued, with pointers to the first address of the process Control block for the next process, and the last process pointer to the Process Control block first address of the first process.

Requires run time--the number of unit times that the process needs to run.

Elapsed time--the number of units of time that the process has been running, with an initial value of "0".

State-There are two states, ready and end, and the initial state is "ready", expressed in "R". When a process finishes running, its state is "end" and is represented by "E".

(2) arbitrarily determine the "required elapsed time" for each process before running the processor scheduler designed.

(3) The five processes are queued sequentially and the queue connection is indicated by the pointer. Another flag unit is used to record the turn to run process. For example, the current turn to P2 execution is:

Sign Unit

K2

K1

Q1

K2

Q2

K3

Q3

K4

Q4

K5

Q5

K2

K3

K4

K5

K1

2

3

1

2

4

1

0

0

0

0

R

R

R

R

R

PCB1

PCB2

PCB3

PCB4

PCB5

(4) Processor scheduling always selects the process that the flag unit indicates to run. Since this experiment is an analog processor scheduling function, the selected process does not actually start running, but rather executes:

Elapsed Time +1

To simulate a run of a process, indicating when the process has been running in one unit.

Please note: In a real system, when a process is selected to run, you must set the time slice value that the process can run, as well as the site of the recovery process, and let it occupy the processor until a wait event occurs or a full time slice is run. This eliminates the need to use "elapsed time +1" to indicate that the process has run full time slices.

(5) Once the process is run, the pointer value in the process control block of the process should be sent to the flag unit to indicate the next turn to the running process. At the same time, you should judge the process's requirements run time and elapsed time, if the process's requirements run time ¹ elapsed time, it is not finished, it should wait until the next round to run. If the process's required run time = elapsed time, it indicates that it has finished executing and should instruct its state to be modified to "end" (E) and exit the queue. At this point, the pointer value in the process control block of the process should be sent to the pointer position of the previous process.

(6) If the process queue in the "Ready" state is not empty, repeat the steps above (4) and (5) until all the processes are in the "End" state.

(7) A display or print statement should be displayed or printed in the program being designed to display or print the process name of each selected process and the change in the process queue once it is run.

(8) A set of "required uptime" for five processes, starting the processor scheduler designed, displaying or printing successive selected process names and the process Control block dynamic change process.

Iv. Report of the experiment

(1) Experimental topics.

(2) The data structure and symbol description used in the program.

(3) Flow chart.

(4) Print a copy of the source program and attach a note.

(5) The initial and running results of the printing program. Requirements are as follows:

Ⅰ the initial state of the process Control block.

Ⅱ Select the running process name and the status of the process control blocks after the selected process runs.

For Ⅱ, it requires that each process be selected to be printed after it has been run.

Experiment 7 allocation and recovery of main memory space

first, the content of the experiment

Allocation and recovery of primary memory space.

ii. purpose of the experiment

A good computer system should not only have a sufficient capacity, high access speed, stable and reliable main memory, but also can reasonably allocate and use these storage space. When the user requests the memory space, the storage management must according to the request of the applicant, according to the certain strategy analysis main memory space usage situation, discovers enough free area allocation to the applicant. When a job evacuation or active return of main memory resources, storage management to recover the main memory space occupied by the job or return some main memory space. Although the implementation of main memory allocation and recovery is related to the management mode of primary storage, this experiment helps students understand how to realize the allocation and recovery of main memory space under different storage management methods.

third, the experiment topic

This experiment simulates the main memory allocation and recovery under two storage management modes.

The first problem is that the main memory allocation and main memory recovery are realized by using the first adaptive algorithm under the variable partition management mode.

[Hint]:

The variable partitioning method divides partitions by the size of the main memory space required by the job. When you want to load a job, check to see if there is enough free space based on the primary stock that the job requires, and if so, divide a partition to assign the job if it is not, and the job cannot be mounted. With the operation of loading, evacuation, main memory space is divided into many partitions, and some partitions are occupied by operations, and some partitions are idle. For example:

<

Operating system

Job 1

p> Job 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.