Tải bản đầy đủ (.pdf) (7 trang)

hệ điều hành trần thị như nguyệt bài tập fork() sinhvienzone com

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (444.37 KB, 7 trang )

When a process creates a new process using the fork() operation, which of the following states is
shared between the parent process and the child process?
a. Stack
b. Heap
c. Shared memory segments
Answer:
Only the shared memory segments are shared between the parent process and the newly forked
child process. Copies of the stack and the heap are made for the newly created process.
-----------------Lưu ý: Để kiểm tra kết quả của tất cả các bài tập bên dưới, sinh viên có thể thực hiện:
▬ Mở hệ điều hành Ubuntu, tạo một file *.c rồi gõ các đoạn code muốn kiểm tra vào (ví dụ
test.c)
▬ Mở cửa sổ Terminal, gõ vào: gcc test.c -o test
▬ Sau đó gõ ./test để chạy file test
-----------------1.

Hỏi output tại LINE A sẽ là gì?

SinhVienZone.com

/>

2.

Bao gồm cả process cha, hỏi đoạn code trên tạo ra bao nhiêu process?
3.

Bao gồm cả process cha, hỏi đoạn code trên tạo ra bao nhiêu process?

SinhVienZone.com

/>



4.
Giả sử pid của process cha và process con lần lượt là 2600 và 2603, hỏi trong đoạn code sau, tại
A, B, C và D giá trị in ra màn hình sẽ là gì?

SinhVienZone.com

/>

5.

Hỏi giá trị in ra màn hình tại LINE X và LINE Y trong đoạn code trên là gì
-----------

SinhVienZone.com

/>

Bài tập từ slide cũ:
1.
a.
Cho đoạn code sau:
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[])
{
int pid;
printf(“hi”);
pid = fork();
if (pid > 0){

fork();
printf(“hello”);
}
else
fork();
printf(“bye”);
}
Hỏi chương trình in ra dòng chữ nào trên màn hình
b.
Thay đổi đoạn code trên thành
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[])
{
int pid;
printf(“hi”);
pid = fork();
if (pid > 0){
fork();
printf(“hello”);
}
else

SinhVienZone.com

/>

{
fork();
printf(“bye”);

}
}
Hỏi chương trình in ra dòng chữ nào trên màn hình
2.
a.
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[])
{
int pid;
printf(“hi”);
pid = fork();
if (pid > 0){
fork();
fork();
printf(“hello”);
}
else
fork();
printf(“bye”);
}
Hỏi chương trình in ra dòng chữ nào trên màn hình
b.
Thay đổi đoạn code trên thành
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[])
{
int pid;
printf(“hi”);

pid = fork();
if (pid > 0){
fork();
fork();

SinhVienZone.com

/>

printf(“hello”);
}
else
{
fork();
printf(“bye”);
}
}
Hỏi chương trình in ra dòng chữ nào trên màn hình
3.
a.
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[])
{
int pid;
printf(“ so 1”);
pid = fork();
printf(“ so 2”);
fork();
if (pid = 0){

fork();
printf(“hello”);
}
else{
fork();
printf(“bye”);
}
}
Hỏi chương trình in ra dòng chữ nào trên màn hình?

SinhVienZone.com

/>


×