View
3
Download
0
Category
Preview:
Citation preview
Recitation Session
Prof. Jin-Soo Kim (jinsookim@skku.edu)
TA - Dong-Yun Lee (dylee@csl.skku.edu)
Computer Systems Laboratory
Sungkyunkwan University
http://csl.skku.edu
2SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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
3SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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?”
4SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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?
5SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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’
6SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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…
7SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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?
8SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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
9SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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
10SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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
11SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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);
}
12SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
IPC Review
IPC (Inter-process communication)
Signal
• Small message that notifies a process that an event occure
Let’s see together..
13SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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
14SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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
15SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
IPC Review (cont’d)
Better if
tail
cat grep
16SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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?”
17SWE2007: Software Experiment 2 | Fall 2016 | Jin-Soo Kim (jinsookim@skku.edu)
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..
Recommended