software experiment 2 - androbenchcsl.skku.edu/uploads/swe2007f16/8-recitation.pdf · swe2007:...
TRANSCRIPT
![Page 1: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/1.jpg)
Recitation Session
Prof. Jin-Soo Kim ([email protected])
TA - Dong-Yun Lee ([email protected])
Computer Systems Laboratory
Sungkyunkwan University
http://csl.skku.edu
![Page 2: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/2.jpg)
2SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
Notice
Some modification in schedule..
• No socket programming
• 1-week break (PA #3 will be uploaded in next week)
Grading
• 10% : Attendance
• 20% : Daily exercise
• 70% : Programming assignment
![Page 3: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/3.jpg)
3SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
Notice
Today, we have recitation class
• What we’ve learned and what we’ve missed
• Questions are always welcomed
• However; before calling me, ask yourself
– “Is this work?”
![Page 4: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/4.jpg)
4SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
What We’ve Learned
OS, Unix-like OS, Linux
File I/O, system call, and FIO
Process
• fork, exit, wait
• exec family..
IPC (Inter-Process Communication)
• Signal, pipe, and fifo
• Socket?
![Page 5: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/5.jpg)
5SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
OS Review
What’s OS?
• Provides an execution environment for running
• OS is HW resource manager
– Which process use CPU?
– How processes use Memory?
– How processes issue I/O? (Storage, Network, Mouse, Printer, etc)
• Unix, Linux
– “Everything is a file”
– OS supports it by ‘File System’
![Page 6: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/6.jpg)
6SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
File Review
Q. How can we communicate with files?
• 1. With standard library (fopen, fread, …)
• 2. Unix I/O (system call)
5 basic Unix I/O
• open, close, read, write, lseek
Let’s see together…
![Page 7: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/7.jpg)
7SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
File Review (cont’d)
Q. Why we use Unix I/O instead of library?
Q. What happen in OS if you call ‘open’ and ‘close’
system call?
• ~ table may be created
• ~ table should be created
Q. What happen if you do not close files after use?
![Page 8: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/8.jpg)
8SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
Process Review
Q. What is process?
• An instance of a program in execution
Create a new process : fork
• fork is interesting functions; return value is different!
void fork2(){
printf("L0\n");fork();printf("L1\n"); fork();printf("Bye\n");
}L0 L1
L1
Bye
Bye
Bye
Bye
![Page 9: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/9.jpg)
9SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
Process Review (cont’d)
Destroying a process : exit
Q. Why is it okay not to call exit explicitly?
Synchronizing processes : wait, waitpid
• If child process is in infinite loop and parent process calls
wait, parent process goes into infinite loop, too
Zombie process
![Page 10: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/10.jpg)
10SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
Process Review (cont’d)
Destroying a process : exit
Q. Why is it okay not to call exit explicitly?
Synchronizing processes : wait, waitpid
• If child process is in infinite loop and parent process calls
wait, parent process goes into infinite loop, too
Zombie processlinux> ps -ef6640 ttyp9 00:00:00 forks <defunct>6641 ttyp9 00:00:00 ps
![Page 11: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/11.jpg)
11SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
Process Review (cont’d)
Running new program
• Process, Program
• execl, execv, and etc…
There is no “RETURN” if exec function success
• Returning means loading new program is failed
main() {if (fork() == 0) {
execl("/bin/ls", "ls", "/", 0);}wait(NULL);printf("completed\n");exit();
}
main() {char *args[] = {"ls", "/", NULL};if (fork() == 0) {
execv("/bin/ls", args);}wait(NULL);
}
![Page 12: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/12.jpg)
12SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
IPC Review
IPC (Inter-process communication)
Signal
• Small message that notifies a process that an event occure
Let’s see together..
![Page 13: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/13.jpg)
13SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
IPC Review (cont’d)
I/O redirection (<, >)
Pipe
• Close pipe after I/O redirection
• If not, process might not be exit (why?)
Let’s see together
![Page 14: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/14.jpg)
14SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
IPC Review (cont’d)
Let’s see what will happen
• cat < /proc/meminfo | grep –i active | tail –n4 > memory.txt
If your design likes below, what will happen?
cat
grep tail
![Page 15: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/15.jpg)
15SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
IPC Review (cont’d)
Better if
tail
cat grep
![Page 16: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/16.jpg)
16SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
Notice
Please consider your algorithm before coding
• Coding is not that important factor!
• Designing is much more important
Questions are always welcomed
• However; before calling me, ask yourself
– “Is this work?”
![Page 17: Software Experiment 2 - AndroBenchcsl.skku.edu/uploads/SWE2007F16/8-recitation.pdf · SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu) 2 Notice Some modification](https://reader034.vdocument.in/reader034/viewer/2022043007/5f95c8f91fe156769a5b5bd3/html5/thumbnails/17.jpg)
17SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim ([email protected])
Exercise
1. Answer 3 questions in page 7
2. Add some functionality to your mini shell
• Built-in tools
• I/O redirection
• $echo “3+3+3” | bc > result
• $cat < /proc/meminfo | grep –i active | tail –n4 > memory.txt
3. Check your grades..