שיתוף PDT בין חוטים PDT Thread A Process Descriptor File Object 1 File Object 2 File 1 File 2 pthread_create Thread B Process Descriptor ה PDT משותף לכל החוטים באותו התהליך לפי סטנדרט pthreads.
שיתוף PDT בין תהליך אבא לתהליך בן 46 PDT Parent Process Descriptor File Object 1 File Object 2 File 1 File 2 fork() 45 Child Process Descriptor 46 PDT 45 ה PDT מועתק מהאב לבן, אבל ה file objects לא מועתקים – הם משותפים. כמובן שאם Child פותח קובץ חדש – זה לא משפיע על Parent.
pipe- תוכנית דוגמא int main() { int my_pipe[2]; int status; char father_buff[6]; pipe(my_pipe); status = fork(); PDT Parent Process Descriptor … File Object 0 File Object 1
pipe- תוכנית דוגמא int main() { int my_pipe[2]; int status; char father_buff[6]; pipe(my_pipe); status = fork(); PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in File Object pipe out
pipe- תוכנית דוגמא int main() { int my_pipe[2]; int status; char father_buff[6]; pipe(my_pipe); status = fork(); PDT Parent Process Descriptor … File Object 0 File Object PDT Child Process Descriptor … File Object pipe in File Object pipe out
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object PDT Child Process Descriptor … /* son process */ if (status == 0) { close(my_pipe[0]); write(my_pipe[1],“BAD",4*sizeof(char)); exit(0); } File Object pipe in File Object pipe out
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object PDT Child Process Descriptor … File Object pipe in File Object pipe out /* son process */ if (status == 0) { close(my_pipe[0]); write(my_pipe[1],“BAD",4*sizeof(char)); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object PDT Child Process Descriptor … File Object pipe in File Object pipe out /* son process */ if (status == 0) { close(my_pipe[0]); write(my_pipe[1],“BAD",4*sizeof(char)); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object PDT Child Process Descriptor … File Object pipe in File Object pipe out /* son process */ if (status == 0) { close(my_pipe[0]); write(my_pipe[1],“BAD",4*sizeof(char)); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in File Object pipe out /* son process */ if (status == 0) { close(my_pipe[0]); write(my_pipe[1],“BAD",4*sizeof(char)); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in File Object pipe out else /* father process */ { close(my_pipe[1]); wait(&status);/* wait until son process finishes */ read(my_pipe[0], father_buff,4*sizeof(char)); printf(“Who’s %s\n", father_buff); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in מוחקים את ה file object כי אין יותר מצביעים אליו else /* father process */ { close(my_pipe[1]); wait(&status);/* wait until son process finishes */ read(my_pipe[0], father_buff,4*sizeof(char)); printf(“Who’s %s\n", father_buff); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in לא מובטח שהבן רץ קודם ולכן מחכים שהבן יסיים לכתוב ל pipe. else /* father process */ { close(my_pipe[1]); wait(&status);/* wait until son process finishes */ read(my_pipe[0], father_buff,4*sizeof(char)); printf(“Who’s %s\n", father_buff); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in else /* father process */ { close(my_pipe[1]); wait(&status);/* wait until son process finishes */ read(my_pipe[0], father_buff,4*sizeof(char)); printf(“Who’s %s\n", father_buff); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in else /* father process */ { close(my_pipe[1]); wait(&status);/* wait until son process finishes */ read(my_pipe[0], father_buff,4*sizeof(char)); printf(“Who’s %s\n", father_buff); exit(0); }
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in else /* father process */ { close(my_pipe[1]); wait(&status);/* wait until son process finishes */ read(my_pipe[0], father_buff,4*sizeof(char)); printf(“Who’s %s\n", father_buff); exit(0); } מה מודפס על המסך ?
pipe- תוכנית דוגמא PDT Parent Process Descriptor … File Object 0 File Object 1 File Object pipe in else /* father process */ { close(my_pipe[1]); wait(&status);/* wait until son process finishes */ read(my_pipe[0], father_buff,4*sizeof(char)); printf(“Who’s %s\n", father_buff); exit(0); } לאו דווקא Who’s BAD. כי לא מובטח ש write כתבה את כל התווים או ש read קראה את כולם...
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); {
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT Child Process Descriptor …
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT Child Process Descriptor …
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT Child Process Descriptor …
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT Child Process Descriptor …
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT Child Process Descriptor … Myfile File Object
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT Child Process Descriptor … Myfile File Object
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT Child Process Descriptor … Myfile File Object
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT … Myfile File Object execv אינה מחליפה את ה PDT של התהליך הקורא !
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT … Myfile File Object /bin/ls Process Descriptor
הכוונת קלט פלט PDT Parent Process Descriptor … File Object 0 File Object 1 status = fork(); if (status == 0) { close(1); fd = open(“myfile”, O_WRONLY…); execv(“/bin/ls”, …); { PDT … Myfile File Object /bin/ls Process Descriptor ועכשיו כל הפלט של ls ילך לקובץ
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); }
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT Shell SON Process Descriptor …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT Shell SON Process Descriptor …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT Shell SON Process Descriptor …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT Shell SON Process Descriptor …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT Shell SON Process Descriptor …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT Shell SON Process Descriptor …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT Shell SON Process Descriptor …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT Shell SON Process Descriptor …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT Shell SON Process Descriptor PDT …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT …
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 int fd[2]; pipe(fd); status = fork(); if (status == 0) { /* first child */ close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execv(“/bin/ls”,…); } Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor /bin/ls OUTPUT
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT
הכוונת קלט פלט PDT Shell Process Descriptor … File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor … נוציא את ה shell מהתמונה כי קשה לראות ככה משהו
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT Shell SON 2 Process Descriptor …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT …
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT … /bin/more Process Descriptor
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT … /bin/more Process Descriptor כעת more יכול לקרוא את מה ש less כתב לו ב pipe
הכוונת קלט פלט 2 File Object 0 File Object 1 Pipe File Object IN Pipe File Object OUT PDT … /bin/ls Process Descriptor status = fork(); if (status == 0) { /* second child */ close(0); dup(fd[0]); close(fd[0]); close(fd[1]); execv(“/bin/more”,..); } close(fd[0]); close(fd[1]); /bin/ls OUTPUT PDT … /bin/more Process Descriptor שתי הפקודות האחרונות המסומנות – הן של ה shell שסוגר את ה pipe כי הוא לא ישתמש בו