Похожие презентации:
Set the Environment VMware+Ubuntu
1.
Set the EnvironmentVMware+Ubuntu
2022.10.19
2.
Set the EnvironmentVmware (option 1 – pro /trial for 30 days):
https://customerconnect.vmware.com/en/downloads/info/slug/desktop_end_
user_computing/vmware_workstation_pro/16_0
3.
Set the EnvironmentVmware (option2- player/free):
https://customerconnect.vmware.com/en/downloads/details?downloadGroup=
WKST-PLAYER-1620&productId=1039&rPId=75725
4.
Ubuntu:https://ubuntu.com/#download
5.
Create a new virtual machine6.
Choose the directory containing the downloaded file7.
Double click the installed system8.
Click the square at the bottom to choose Terminalor simply click right button on desktop
9.
Try some commands10.
Experiment 1Linux operations and process creation
11.
Basic Information• Experiment Name
• Linux operations and process creation
• Experiment Purpose
• Master basic commands in Linux
• Master the way to edit, compile and execute programs in Linux
• Understand the system call fork()
• Experiment Requirements
• Try to execute some basic commands and analyze the results
• Use gcc to compile a program with fork() and analyze the
output
• 4 Classes
• Experiment Environment: VMWare + Linux (Ubuntu)
12.
Experiment Environment• Click right button on mouse in the blank area and choose “open
in terminal”. Then try some commands and record the result.
13.
Experiment Content-I• Use Ctrl+Alt to switch between Windows and Ubuntu
• Basic common commands
• Directory operations
• ls [-arg][dirName] //list the content of the working
directory, e.g. type ”ls -l” to list the details
• pwd //check what the current directory is
• cd [dirName] //change the working directory, e.g. type
“cd ..” to go to the parent directory
• du [dirName] //check the size of the directory
14.
Experiment Content-I• Basic common commands
• File operations
• cat fileName //print the content of a file
• rm filename //remove a file
• cp [-arg] sourceFileName destinationFileName //copy a
file from the source to the destination
• mv sourceFileName destinationFileName //move a file
from the source to the destination
• ln sourceFileName destinationFileName //link a file from
the source to the destination
15.
Experiment Content-I• Basic common commands
• Process operations
• ps [-arg] //check the current processes in the shell
• kill pid //kill the process which process id is “pid”
• Get help information of a command
• man command (type “q” to quit)
• command --help
16.
Experiment Content-II• Type the following code in the created file and save it
17.
Experiment Content-II• Compile
• Type gcc sourFileName –o executionFileName //compile a c
file to get an execution file
• Or type gcc sourceFileName //automatically compiled to
“a.out”
• Execute
• Type ./executionFileName //execute the file, e.g. “./a.out”
• In “./a.out”, “.” represents the current working directory.
• Or try to type the absolute path name of the obtained
execution file
18.
Experiment Content-II19.
Experiment Content-II• During the execution
• Use Ctrl+Z to suspend the execution and then type “fg” to
resume it (optional)
• Suspend a process and type “ps” to see the information of
this process in shell
• Use Ctrl+C to terminate the execution
20.
About fork()• Fork() is used for creating a new process (child process)
• The process that makes the fork() call is the parent process
• both processes execute the next instruction following the fork()
system call
• A child process uses the same pc(program counter), same CPU
registers, same open files which use in the parent process
• It takes no parameters and returns an integer value
• Negative Value: unsuccessful
• Zero: Returned to the newly created child process
• Positive value: Returned to parent or caller. The value
contains process ID of newly created child process
21.
About fork()• Try to predict what the output will be before execute it
22.
Experiment 2Interprocess Communication
23.
Basic Information• Experiment Name
• Interprocess Communication
• Experiment Purpose
• Master the way to communicate between two processes by
sending messages
• Experiment Requirements
• Use gcc to compile two programs (server.c and client.c) with
msgget(), msgsnd(), and msgrcv()
• Execute the file for server.c in background first and then
execute the file for client.c. Analyze the output
• 4 Classes
• Experiment Environment: VMWare + Linux (Ubuntu)
24.
Experiment Content• Edit two files and execute them as follows
25.
Experiment Content• getpid() is used to get the pid of the current process
• msgget(key, flag) is used either to create a new message queue
or to locate an existing queue based on a key
• msgqid=msgget(MSGKEY, 0777)
• msgqid=msgget(MSGKEY, 0777|IPC_CREAT) //Create the
queue if it doesn't already exist in the kernel
• msgsnd(msgqid,msgp,size,flag) is used to send a message (msgp)
to a message queue (msgqid)
• msgsnd(msgqid,&msg,sizeof(int),0) (in both client.c and
server.c)
26.
Experiment Content• msgrcv(msgqid, msgp, size, type, flag) is used to receive a
message (msgp) from a message queue (msgqid)
• msgtyp specifies the type of message requested
• If msgtyp is 0, then the first message in the queue is read.
• If msgtyp is greater than 0, then the first message in the
queue of type msgtyp is read
• If msgtyp is less than 0, then the first message in the
queue with the lowest type less than or equal to the
absolute value of msgtyp will be read
• msgrcv(msgqid,&msg,256,pid,0) (in client.c)
• msgrcv(msgqid,&msg,256,1,0) (in server.c)
27.
Experiment Content• Compile and Execution
• gcc –o executionFileName sourFileName //compile a c file to
get an execution file
• gcc sourceFileName //automatically compiled to “a.out”
• ./executionFileName //execute the file, e.g. “./a.out”
• Use Ctrl+Z to suspend the execution and then type “fg” to
resume it
• Suspend a process and type “ps” to see the information of
this process in shell
• Use Ctrl+C to terminate the execution
28.
29.
Experiment 3Page Replacement Algorithms
30.
Basic Information• Experiment Name
• Page Replacement Algorithms
• Experiment Purpose
• Master the basic idea of multiple page replacement algorithms
and know how to implement one of them
• Experiment Requirements
• Write a program to determine the content of page frames for
inputted page reference string based on one of PRAs
• Use gcc to compile it and analyze the output of execution
(need to input the frame number and reference string)
• 4 Classes
• Experiment Environment: VMWare + Linux (Ubuntu)
31.
Experiment ContentFramework of the program:
• For each page in the page reference string (array prs[i])
• Check if it is in the frames (array fr[j])
• If it’s in one frame, continue to check the next page
• If it is not, check if there is an empty frame (fr[j]=-1)
• Yes put the page into the empty frame (fr[j]=prs[i])
• No based on a certain algorithm (OPT, FIFO, or LRU),
select a page from the frames and then replace this
page with the new page (find j to put prs[i] in fr[j])
32.
Experiment 4File System Operations and Design
33.
Basic Information• Experiment Name
• File System Operations and Design
• Experiment Purpose
• Master how to design and implement a simple file system
which can provide several basic operations on a file
• Experiment Requirements
• Write a program to build a simple file system based on a few
relevant system calls, such as creat, unlink, read, write, open,
and close.
• Use gcc to compile it and analyze the output of execution
(need to use the provided commands to create, read , write,
and delete a file)
• 4 Classes; Experiment Environment: VMWare + Linux
34.
Experiment Content• Create a file: fd=creat (filenamep, mode);
• Delete a file: unlink (filenamep);
• Read a file: fd=open (filenamep, mode);
nr=read (fd, buf, count);
close (fd);
• Write a file: fd=open (filenamep, mode);
nw=write (fd, buf, count);
close (fd);
35.
#include <sys/types.h>#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <dirent.h>
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
#define BUFFSIZE 1024
#define MAX_FILENAME_LEN 100
void create_file(const char *fileName)
{
if(creat(fileName,FILE_MODE) < 0)
{
printf("Create file failed!\n");
}
else
{
printf("Create file successfully!\n");
}
}
void del_file(const char *fileName)
{
if(unlink(fileName) < 0)
{
printf("Delete file failed!\n");
}
else
{
printf("Delete file successfully!\n");
}
}
void print_file(const char *fileName)
{
int fd = -1;
int n;
char buf[BUFFSIZE];
fd = open(fileName,O_RDONLY);
if(fd < 0)
{
printf("Open file failed!\n");
return;
}
while((n=read(fd,buf,BUFFSIZE)) > 0)
{
if(write(STDOUT_FILENO,buf,n) != n)
{
printf("write error!\n");
return;
}
}
36.
Install gcc in Ubuntu by execute a simple command37.
If it doesn’t workYou might try to set another server to get the packages---Click
circled “Software&Updates”
38.
Click circled menu to choose a server nearbyI choose huaweicloud, you are free to try others (near to your location)
39.
40.
If there are some errors to get the packagesYou might try the following commands first
41.
Run “gcc –version” to check the versionThen you can run command such as “gcc 1.c –o 1” to compile a c file
42.
You might need to share some files between Ubuntu and Windows43.
You might need to share some files between Ubuntu and WindowsShared directory
in Windows
44.
Use touch to create a new file in your default working directoryCopy a file into /mnt/hgfs/YourDirName
Then you can see it in Windows
Double click to edit the file
In shared directory in Windows