Nguyên lý hệ điều hành
Lý thuyết
- Bài 1: Giới thiệu về hệ điều hành
- Bài 2: Quản lý tiến trình
- Bài 3: Quản lý bộ nhớ
- Bài 4: Hệ thống tệp
- Bài 5: Hệ thống I/O
- Bài 6: Deadlock
Chú ý: slides các chương được gửi qua email, các em kiểm tra thư (Gmail) để tải về.
Thực hành
Bài 1. Chạy chương trình viết bằng ngôn ngữ C: “An example program Using File System Calls”, giáo trình Modern Operating System, trang 390 (bản 2e), trang 263 (bản 3e). Nội dung chương trình như sau:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* File copy program. Error checking and reporting is minimal. */
#include <sys/types.h> /* include necessary header files */
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <stdio.h>
int main(int argc, char *argv[]); /* ANSI prototype */
#define BUF_SIZE 4096 /* use a buffer size of 4096 bytes */
#define OUTPUT_MODE 0700 /* protection bits for output file */
int main(int argc, char *argv[])
{
int in_fd, out_fd, rd_count, wt_count;
char buffer[BUF_SIZE];
if (argc!=3) exit(1); /* syntax error if argc is not 3 */
/* Open the input file and create the output file */
in_fd=open(argv[1], O_RDONLY); /* open the source file */
if (in_fd<0) exit(2); /* if it cannot be opened, exit */
out_fd=creat(argv[2], OUTPUT_MODE); /* create the destination file */
if (out_fd<0) exit(3); /* if it cannot be created, exit */
/* Copy loop */
while (TRUE) {
rd_count=read(in_fd, buffer, BUF_SIZE); /* read a block if data */
if (rd_count<=0) break; /* if end of file or error, exit loop */
wt_count=write(out_fd, buffer, rd_count); /* write data */
if (wt_count<=0) exit(4); /* wt_count<=0 is an error */
}
/* Close the files */
close(in_fd);
close(out_fd);
if (rd_count==0) /* no error on last read */
exit(0);
else
exit(5); /* error on last read */
}
Yêu cầu:
- Đưa ra thông báo lỗi khi không nhập đủ tên file nguồn, file đích;
- Kiểm tra, nếu đối tượng yêu cầu copy không tồn tại hoặc là thư mục thì không copy, và đưa ra thông báo lỗi giống như khi sử dụng lệnh cp trong Linux;
- Đặt thiết lập các quyền permission cho file mới tạo ra như sau: rw-rw-rw-
Bài 2. Viết một Shell script để tạo ra menu tương tác với người dùng gồm 5 lựa chọn như sau (mỗi lựa chọn được 2 điểm):
[1] Show information about your group (name, student ID, class) [2] Show today date/time [3] Show all files in current directory [4] Show calendar [5] Exit/Stop
Tùy vào lựa chọn của người dùng, chương trình đưa ra thông tin tương ứng, nếu người dùng chọn từ 1-4 thì sau khi thực hiện xong một việc phải quay lại để người dùng chọn chức năng tiếp theo. Chỉ khi ấn số 5 thì chương trình mới thoát. Đặt tên script là group-_n_.sh, ví dụ: nhom-3.sh