You are on page 1of 4

Báo cáo thực hành môn Hệ điều hành - Giảng viên: Trần Hoàng Lộc.

Họ và tên: Mai Đăng Minh


Mã số sinh viên: 21522340
Lớp: CTTT2021

HỆ ĐIỀU HÀNH
BÁO CÁO LAB 5

CHECKLIST
5.5. BÀI TẬP THỰC HÀNH
BT 1

Trình bày cách làm

Chụp hình minh chứng

Giải thích kết quả

1
Báo cáo thực hành môn Hệ điều hành - Giảng viên: Trần Hoàng Lộc.

6. BÀI TẬP THỰC HÀNH


Code:

2
Báo cáo thực hành môn Hệ điều hành - Giảng viên: Trần Hoàng Lộc.

Result:

3
Báo cáo thực hành môn Hệ điều hành - Giảng viên: Trần Hoàng Lộc.

Explain:
-The program displays the prompt "21522340>" to indicate that the user should input a
command.
-The program reads a line of input from the user, storing it in the input array. fgets is used
to ensure that the input does not exceed the maximum line length (MAX_LINE).
-The input line is tokenized into individual words (command-line arguments) using
spaces, tabs, and newline characters as delimiters. The tokens are stored in the args array,
and the array is terminated with a NULL pointer, preparing it for use with the execvp
function.
-The program checks if the last token is "&," indicating that the user wants the command
to run in the background. If "&" is found, it is removed from the arguments, and the
background flag is set to 1.
-The program forks a new process. In the child process, it executes the command using
execvp. If the execution fails, an error message is printed, and the child process exits. In
the parent process, it waits for the child process to finish unless the command is running
in the background.
-The program repeats the entire process in a loop, prompting the user for input, parsing
the input, and executing commands until the user decides to exit.
-Note: The termination condition for the loop (run variable) is not explicitly shown in the
provided code snippet. You might have additional code not included in your snippet for
handling the exit condition.

Link video

You might also like