process new
DESCRIPTION
New Process Gear became part of New Venture Gear, the first joint manufacturing effort between leading U.S. automakers.TRANSCRIPT
![Page 1: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/1.jpg)
1
3.A Quaûn lyù quaù trình
Khaùi nieäm cô baûn
Ñònh thôøi CPU
Caùc taùc vuï cô baûn: taïo/keát thuùc quaù trình
Söï coäng taùc giöõa caùc quaù trình
Giao tieáp giöõa caùc quaù trình
![Page 2: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/2.jpg)
2
Khaùi nieäm cô baûn
Heä thoáng maùy tính thöïc thi nhieàu chöông trình khaùc nhau
● Batch system: job
● Time-shared system: user program, task
Quaù trình (process)
● moät chöông trình ñang thöïc thi
Moät quaù trình ñöôïc ñònh nghóa bôûi
● Traïng thaùi CPU (trò cuûa caùc thanh ghi)
● Khoâng gian ñòa chæ (noäi dung boä nhôù)
● Moâi tröôøng (environment, xaùc ñònh thoâng qua caùc baûng cuûa heä
ñieàu haønh)
![Page 3: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/3.jpg)
3
Khaùi nieäm cô baûn (tt)
Traïng thaùi CPU
● Processor Status Word (PSW)
● Instruction Register (IR)
● Program Counter (PC)
● Stack Pointer (SP)
● Caùc general purpose register
Khoâng gian ñòa chæ
● Text (code)
● Data
● Heap
● Stack
Moâi tröôøng
● Vd: terminal ñang duøng, caùc open file, caùc keânh giao tieáp vôùi caùc
quaù trình khaùc
● Ñöôïc lieät keâ trong caùc baûng cuûa heä ñieàu haønh
![Page 4: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/4.jpg)
4
Process control block
Heä ñieàu haønh löu thoâng tin veà quaù trình trong process
control block (PCB)
D.Feitelson
![Page 5: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/5.jpg)
5
Caùc böôùc naïp chöông trình vaøo boä nhôù
![Page 6: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/6.jpg)
6
Töø chöông trình ñeán quaù trình
Chöông trình thöïc thi coù ñònh daïng load module maø trình
naïp (loader) “hieåu” ñöôïc
● Vd ñònh daïng elf trong Linux
Layout luaän lyù cuûa process image
program
code
data
Executable binary file
(load module)
Process image
trong main memory
start address
program
code
data
stack
heap
![Page 7: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/7.jpg)
7
Khôûi taïo quaù trình
Caùc böôùc heä ñieàu haønh khôûi taïo quaù trình
● Caáp phaùt moät ñònh danh duy nhaát (process number hay process
identifier, pid) cho quaù trình
● Caáp phaùt khoâng gian nhôù ñeå naïp quaù trình
● Khôûi taïo khoái döõ lieäu Process Control Block (PCB) cho quaù trình
● Thieát laäp caùc moái lieân heä caàn thieát (vd: saép PCB vaøo haøng ñôïi
ñònh thôøi,…)
![Page 8: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/8.jpg)
8
Caùc traïng thaùi cuûa quaù trình (1/2)
Caùc traïng thaùi cô baûn cuûa moät quaù trình:
● new: quaù trình vöøa ñöôïc taïo
● ready: quaù trình ñaõ coù ñuû taøi nguyeân, chæ coøn caàn CPU
● running: caùc leänh cuûa quaù trình ñang ñöôïc thöïc thi
● waiting: hay laø blocked, quaù trình ñôïi I/O hoaøn taát, hay ñôïi tín hieäu
● terminated: quaù trình ñaõ keát thuùc
![Page 9: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/9.jpg)
9
Caùc traïng thaùi cuûa quaù trình (2/2)
ready running
dispatch
interrupt
I/O or event
completion
I/O or event
wait
new terminated
waiting
admit exit
Chuyeån ñoåi giöõa caùc traïng thaùi cuûa quaù trình
![Page 10: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/10.jpg)
10
Ví duï veà traïng thaùi quaù trình
/* test.c */
int main(int argc, char** argv)
{
printf(“Hello world\n");
exit(0);
}
Bieân dòch chöông trình trong Linux
gcc test.c –o test
Thöïc thi chöông trình test
./test
Trong heä thoáng seõ coù moät quaù trình
test ñöôïc taïo ra, thöïc thi vaø keát
thuùc.
Chuoãi traïng thaùi cuûa quaù
trình test nhö sau (tröôøng
hôïp toát nhaát):
● new
● ready
● running
● waiting (do chôø I/O khi goïi
printf)
● ready
● running
● terminated
![Page 11: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/11.jpg)
11
Process Control Block
Ñaõ thaáy laø moãi quaù trình trong heä thoáng ñeàu ñöôïc caáp
phaùt moät Process Control Block (PCB)
PCB laø moät trong caùc caáu truùc döõ lieäu
quan troïng nhaát cuûa heä ñieàu haønh
Ví duï layout cuûa moät PCB:
(tröôøng pointer duøng ñeå lieân
keát caùc PCB thaønh moät
linked list)
Moâi tröôøng
![Page 12: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/12.jpg)
12
Caùc tröôøng tieâu bieåu cuûa PCB
Tanenbaum
![Page 13: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/13.jpg)
13
Chuyeån ngöõ caûnh (1/2)
Laøm theá naøo ñeå chia seû CPU giöõa caùc quaù trình?
Ngöõ caûnh (context) cuûa moät quaù trình laø tình traïng hoaït
ñoäng cuûa quaù trình
● Trò cuûa caùc thanh ghi, trò cuûa program counter, boä nhôù,…
Ngöõ caûnh cuûa quaù trình ñöôïc löu trong PCB cuûa noù
Chuyeån ngöõ caûnh (context switch) laø coâng vieäc ngöng
quaù trình ñang thöïc thi vaø chaïy moät quaù trình khaùc. Khi
ñoù caàn:
● löu ngöõ caûnh cuûa quaù trình vaøo PCB cuûa noù
● naïp ngöõ caûnh töø PCB cuûa quaù trình môùi ñeå quaù trình môùi thöïc thi
![Page 14: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/14.jpg)
14
Chuyeån ngöõ caûnh (2/2)
![Page 15: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/15.jpg)
15
Yeâu caàu ñoái vôùi heä ñieàu haønh veà quaûn lyù quaù trình
Hoã trôï söï thöïc thi luaân phieân giöõa nhieàu quaù trình
● Khi naøo choïn vaø choïn quaù trình naøo ñeå thöïc thi coù theå tuøy thuoäc
vaøo tieâu chí nhö
Hieäu suaát söû duïng CPU
Thôøi gian ñaùp öùng
…
Phaân phoái taøi nguyeân heä thoáng hôïp lyù
● Vaán ñeà deadlock, trì hoaõn voâ haïn ñònh,…
Cung caáp cô cheá hoã trôï user taïo/keát thuùc quaù trình
Cung caáp cô cheá ñoàng boä vaø giao tieáp giöõa caùc quaù trình
![Page 16: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/16.jpg)
16
running
ready
waiting
Quaûn lyù quaù trình: caùc haøng ñôïi
7
11 4 2 17
19 11
process number
caùc PCB Ví duï
![Page 17: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/17.jpg)
17
Ñònh thôøi quaù trình
Taïi sao phaûi ñònh thôøi?
● Multiprogramming
Coù nhieàu quaù trình thöïc thi luaân phieân nhau
Muïc tieâu (ví duï): cöïc ñaïi hieäu suaát söû duïng cuûa CPU
● Time-sharing
User töông taùc vôùi quaù trình
Muïc tieâu: toái thieåu thôøi gian ñaùp öùng
Moät soá khaùi nieäm cô baûn
● Caùc boä ñònh thôøi (scheduler)
● Caùc haøng ñôïi ñònh thôøi (scheduling queue)
![Page 18: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/18.jpg)
18
Caùc haøng ñôïi ñònh thôøi
Job queue
Ready queue
Caùc device queue
…
![Page 19: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/19.jpg)
19
Caùc taùc vuï ñoái vôùi quaù trình (1/4)
Taïo quaù trình môùi
● Quaù trình coù theå taïo moät quaù trình môùi thoâng qua moät system call
(vd: haøm fork trong UNIX)
Ví duï: (UNIX) Khi user ñaêng nhaäp heä thoáng, moät command
interpreter (shell) seõ ñöôïc taïo ra cho user
Quaù trình ñöôïc taïo laø quaù trình con cuûa quaù trình taïo (quaù trình
cha). Quan heä cha-con ñònh nghóa moät caây quaù trình.
![Page 20: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/20.jpg)
20
Caây quaù trình trong Linux/Unix
root
swapper pagedaemon init
bash bash bash
mkdir grep ls gcc
Ví duï
![Page 21: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/21.jpg)
21
Caùc taùc vuï ñoái vôùi quaù trình (2/4)
Taïo quaù trình môùi (tt)
● Chia seû taøi nguyeân cuûa quaù trình cha: caùc khaû naêng
Quaù trình cha vaø con chia seû moïi taøi nguyeân
Quaù trình con chia seû moät phaàn taøi nguyeân cuûa cha
Cha vaø con khoâng chia seû taøi nguyeân
● Trình töï thöïc thi: hai khaû naêng
Quaù trình cha vaø con thöïc thi ñoàng thôøi (concurrently)
Quaù trình cha chaïy khi quaù trình con keát thuùc
● Trong Unix, quaù trình goïi fork seõ ñöôïc taïo moät quaù trình con
hoaøn toaøn gioáng noù vaøo thôøi ñieåm goïi --- cuøng traïng thaùi CPU,
khoâng gian ñòa chæ, moâi tröôøng
chæ khaùc nhau ôû process ID vaø trò traû veà töø fork
![Page 22: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/22.jpg)
22
Caùc taùc vuï ñoái vôùi quaù trình (3/4)
Taïo quaù trình môùi (tt)
● Khoâng gian ñòa chæ: tuøy heä ñieàu haønh
UNIX: Khoâng gian ñòa chæ cuûa quaù trình con ñöôïc nhaân baûn töø
khoâng gian ñòa chæ cuûa cha vaøo thôøi ñieåm goïi
Windows: phöùc taïp hôn, Win32 API CreateProcess() caàn 10
tham soá
BOOL WINAPI CreateProcess(
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
![Page 23: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/23.jpg)
23
Veà quan heä cha/con
Ví duï aùp duïng fork trong UNIX/Linux
● Quaù trình goïi fork() ñeå taïo moät quaù trình con
● Quaù trình con goïi exec() ñeå naïp vaø thöïc thi moät chöông trình
trong khoâng gian nhôù cuûa noù
● Quaù trình cha laøm vieäc khaùc… hay goïi wait() ñeå ñôïi con xong
ñoàng boä
![Page 24: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/24.jpg)
24
Ví duï taïo process vôùi fork()
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[]){
int return_code;
/* create a new process */
return_code = fork();
if (return_code > 0){
printf(“This is parent process”);
wait(NULL);
exit(0);
}
else if (return_code == 0){
printf(“This is child process”);
execlp(“/bin/ls”, “ls”, NULL);
exit(1);
}
else {
printf(“Fork error\n”);
exit(1);}
}
![Page 25: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/25.jpg)
25
int main() {
printf(“Hello world \n”);
fork();
printf("Hello world \n”);
fork();
return 0;
}
}
![Page 26: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/26.jpg)
26
Caùc taùc vuï ñoái vôùi quaù trình (4/4)
Taïo quaù trình môùi
Keát thuùc quaù trình
● Quaù trình töï keát thuùc
Quaù trình keát thuùc khi thöïc thi leänh cuoái vaø goïi system routine
exit
● Quaù trình keát thuùc do quaù trình khaùc (coù ñuû quyeàn, vd: quaù trình
cha cuûa noù)
Goïi system routine abort vôùi tham soá laø pid (process identifier)
cuûa quaù trình caàn ñöôïc keát thuùc
● Heä ñieàu haønh thu hoài taát caû caùc taøi nguyeân cuûa quaù trình keát
thuùc (vuøng nhôù, I/O buffer,…)
![Page 27: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/27.jpg)
27
Coäng taùc giöõa caùc quaù trình
Caùc quaù trình coù theå coäng taùc (cooperate) ñeå hoaøn thaønh
coâng vieäc
● Vd
Sampler Sensor Sensor data
buffer Process data
Display
Shared memory
![Page 28: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/28.jpg)
28
Coäng taùc giöõa caùc quaù trình
Thieát keá öùng duïng
● Phaân chia moät öùng duïng lôùn thaønh caùc process coäng taùc nhau
kieán truùc client-server
AÙp duïng coäng taùc giöõa caùc quaù trình ñeå
● Baøi toaùn producer-consumer
● Modul hoùa
● Taêng toác tính toaùn
Neáu heä thoáng coù nhieàu CPU, chia coâng vieäc tính toaùn thaønh
nhieàu coâng vieäc tính toaùn nhoû chaïy song song
Söï coäng taùc giöõa caùc quaù trình ñoøi hoûi heä ñieàu haønh
cung caáp giaûi phaùp ñoàng boä hoaït ñoäng (chöông 3) vaø
giao tieáp cho caùc quaù trình
![Page 29: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/29.jpg)
29
Baøi toaùn producer-consumer
Baøi toaùn tieâu bieåu veà söï coäng taùc giöõa caùc quaù trình: baøi
toaùn producer-consumer
● Producer taïo ra caùc döõ lieäu vaø consumer tieâu thuï / söû duïng caùc
döõ lieäu ñoù. Söï trao ñoåi döõ lieäu ñöôïc thöïc hieän qua buffer
unbounded buffer: kích thöôùc buffer voâ haïn (khoâng thöïc teá)
bounded buffer: kích thöôùc buffer coù haïn
● Producer vaø consumer phaûi hoaït ñoäng ñoàng boä vì
Consumer khoâng ñöôïc tieâu thuï khi producer chöa saûn xuaát
Producer khoâng ñöôïc taïo theâm döõ lieäu khi buffer ñaày
![Page 30: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/30.jpg)
30
Interprocess communication (IPC)
IPC laø caùc kyõ thuaät cung caáp bôûi heä ñieàu haønh nhaèm
giuùp caùc quaù trình giao tieáp vôùi nhau
● Caùc quaù trình coù theå treân cuøng maùy hoaëc khaùc maùy
Hai kyõ thuaät IPC
● Truyeàn thoâng ñieäp (message passing)
● Duøng boä nhôù chia seû (shared memory)
![Page 31: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/31.jpg)
3.4 Fig 3.12
Moâ hình giao tieáp
Dùng bộ nhớ chia sẻ Truyền thông điệp
![Page 32: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/32.jpg)
32
Truyeàn thoâng ñieäp
Caùc vaán ñeà
● Naming
Giao tieáp tröïc tieáp
– send(P, msg): göûi thoâng ñieäp ñeán quaù trình P
– receive(Q, msg): nhaän thoâng ñieäp ñeán töø quaù trình Q
Giao tieáp giaùn tieáp: thoâng qua mailbox hay port
– send(A, msg): göûi thoâng ñieäp ñeán mailbox A
– receive(B, msg): nhaän thoâng ñieäp töø mailbox B
● Synchronization:
blocking/nonblocking send
blocking/nonblocking receive
![Page 33: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/33.jpg)
33
Example of shared memory for IPC
POSIX Shared Memory
● Process first creates shared memory segment
segment_id = shmget(IPC_PRIVATE, size, S_IRUSR |
S_IWUSR);
● Process wanting access to that shared memory must attach to it
shared_memory = (char *) shmat(id, NULL, 0);
● Now the process could write to the shared memory
sprintf(shared_memory, "Writing to shared memory");
● When done a process can detach the shared memory from its
address space
shmdt(shared_memory);
![Page 34: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/34.jpg)
34
Giao tieáp trong heä thoáng client-server
Socket
Remote Procedure Call (RPC)
Remote Method Invocation (RMI)
![Page 35: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/35.jpg)
35
Socket
Socket laø moät ñoái töôïng tröøu töôïng duøng ñeå töôïng tröng
moät ñaàu cuoái cuûa moät keânh giao tieáp
● Goàm ñòa chæ IP vaø port number
● Vd socket 161.25.19.8:1625 duøng ñeå tham chieáu port 1625 treân
maùy coù ñòa chæ IP 161.25.19.8
![Page 36: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/36.jpg)
36
Socket
● (tt) ‘well-known’ port xaùc ñònh caùc dòch vuï chuaån
● Cung caáp cô cheá giao tieáp möùc thaáp: göûi nhaän moät chuoãi byte döõ
lieäu khoâng caáu truùc
● Hai loaïi giao tieáp qua socket: connectionless vaø connection-
oriented
![Page 37: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/37.jpg)
37
Göûi/nhaän qua socket
Haøm thö vieän Dieãn giaûi
socket() Taïo moät socket
bind() Gaùn moät ñòa chæ cuïc boä vaøo socket
listen() Saün saøng ñeå chaáp nhaän keát noái
accept() (server) Chôø keát noái ñeán töø client
connect() (client) keát noái ñeán moät server
send()
sendto()
Göûi döõ lieäu qua keânh giao tieáp ñaõ thieát laäp
Göûi döõ lieäu ñeán moät ñòa chæ
recv()
recvfrom()
Nhaän döõ lieäu qua keânh giao tieáp ñaõ thieát laäp
Nhaän döõ lieäu ñeán töø moät ñòa chæ
close() Ñoùng keát noái
![Page 38: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/38.jpg)
38
Connectionless Transport Service
sendto(socket, buffer, buffer_length, flags, destination_address,
addr_len)
recvfrom(socket, buffer, buffer_length, flags, from_address,
addr_len)
socket()
bind()
Process A
sendto()/
recvfrom()
socket()
bind()
Process B
sendto()/
recvfrom()
close() close()
![Page 39: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/39.jpg)
39
Connection-Oriented Transport Service
send(socket, buffer, buffer_length, flags)
recv(socket, buffer, buffer_length, flags)
socket() bind() listen() accept() recv() send() close()
Server (Google)
socket() connect() send() recv() close()
Client (Firefox)
communication
![Page 40: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/40.jpg)
40
Remote procedure call (RPC)
Môû roäng cô cheá goïi thuû tuïc (procedure call) thoâng
thöôøng
● Duøng RPC moät quaù trình coù theå goïi moät thuû tuïc naèm treân maùy
tính ôû xa qua maïng
Caùc vaán ñeà khi hieän thöïc RPC
● Truyeàn tham soáû
● Bieåu dieãn döõ lieäu
● Keát noái töø client ñeán server (binding)
● Giao thöùc vaän chuyeån
● Xöû lyù loãi (exception handling)
● An toaøn (security)
![Page 41: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/41.jpg)
41
Hieän thöïc RPC: caùc stub
D.Feitelson
g
Client Server
![Page 42: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/42.jpg)
42
Hieän thöïc RPC: löu ñoà thôøi gian
Client
Server
Goïi remote
procedure
Request Reply
Keát quaû traû veà
chôø keát quaû traû veà
(suspended)
Goïi thuû tuïc cuïc boä
vaø traû veà keát quaû
(blocked) (blocked)
Thời gian
![Page 43: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/43.jpg)
43
Marshalling / Unmarshalling
Marshalling laø coâng vieäc ñoùng goùi döõ lieäu vaøo trong moät
thoâng ñieäp döôùi moät ñònh daïng thích hôïp ñeå vaän chuyeån
qua maïng
● Unmarshalling laø coâng vieäc ngöôïc laïi
Duøng marshalling / unmarshalling trong hieän thöïc RPC
trong caùc coâng ñoaïn
● Göûi yeâu caàu ñeán server
Client stub ñoùng goùi caùc tham soá cuûa thuû tuïc vaøo trong goùi
thoâng ñieäp vaø göûi noù ñeán server stub
Server stub môû goùi laáy caùc tham soá töø thoâng ñieäp vaø duøng
chuùng ñeå goïi thuû tuïc cuûa server
● Server traû veà keát quaû
Server stub ñoùng goùi keát quaû tröôùc khi göûi ñeán client stub
Client stub môû goùi laáy keát quaû vaø chuyeån noù ñeán client
![Page 44: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/44.jpg)
44
Marshalling / Unmarshalling
return reply call request
message to
result
parameters
to message
Client Stub
Client
receive send
Server
return reply call request
message to
parameters
result
to message
Server Stub
receive send
Transport
(OS 2) Transport
(OS 1)
network
![Page 45: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/45.jpg)
45
Hieän thöïc RPC: bieåu dieãn döõ lieäu
Döõ lieäu treân caùc heä thoáng khaùc nhau coù theå ñöôïc bieåu
dieãn khaùc nhau
● Maõ hoùa kyù töï: ASCII, EBCDIC
● Ví duï bieåu dieãn 32-bit integer trong boä nhôù
Motorola: big-endian most significant byte taïi high memory
address ()
Intel x86: little-endian least significant byte taïi high memory
address ()
Giaûi phaùp: maõ hoùa döõ lieäu duøng daïng bieåu dieãn ñoäc laäp
maùy XDR (External Data Representation) khi trao ñoåi döõ
lieäu giöõa caùc heä thoáng maùy khaùc nhau
![Page 46: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/46.jpg)
46
Remote method invocation (RMI)
Cho pheùp moät chöông trình Java coù theå goïi moät phöông
thöùc (method) cuûa moät ñoái töôïng ôû xa, nghóa laø moät ñoái
töôïng ôû taïi moät maùy aûo Java khaùc
![Page 47: Process New](https://reader031.vdocuments.mx/reader031/viewer/2022020222/563dbbb9550346aa9aafb23c/html5/thumbnails/47.jpg)
47
Marshalling tham soá trong RMI
Phöông thöùc ñöôïc trieäu goïi coù daïng sau:
boolean someMethod(Object x, Object y)
marshalling unmarshalling