COMP 3000 2012 Week 8 Notes: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Some answers to the practice questions | Some answers to the practice questions | ||
1) | 1) | ||
Q: You can create a sparse file in UNIX by writing sequences of zeros to a file. | Q: You can create a sparse file in UNIX by writing sequences of zeros to a file. | ||
Line 9: | Line 10: | ||
2) | 2) | ||
Q: Are environment variables ``global variables? Specifically, if you change the value of an environment variable X in one process, what happens to the value of X in other processes? | Q: Are environment variables ``global variables? Specifically, if you change the value of an environment variable X in one process, what happens to the value of X in other processes? | ||
Line 15: | Line 17: | ||
3) | 3) | ||
Q: In UNIX, there are three permissions associated with the user, the user's group, and everyone else. What are those three permissions? | Q: In UNIX, there are three permissions associated with the user, the user's group, and everyone else. What are those three permissions? | ||
Line 20: | Line 23: | ||
4) | 4) | ||
Q: If you see a zombie process during normal system operation, how can you get rid of it? | Q: If you see a zombie process during normal system operation, how can you get rid of it? | ||
Line 26: | Line 30: | ||
5) | 5) | ||
Q: I can copy a file using I/O redirection as follows: cat /bin/ls > bar. If I now type ./bar, it won't run. However, if I run another command before typing ./bar, I will get | Q: I can copy a file using I/O redirection as follows: cat /bin/ls > bar. If I now type ./bar, it won't run. However, if I run another command before typing ./bar, I will get | ||
a file listing. What needed to be changed to get bar to run? | a file listing. What needed to be changed to get bar to run? | ||
Line 33: | Line 38: | ||
6) | 6) | ||
Q: System calls cannot normally be made using standard function calls. What CPU mechanism is used by regular processes to invoke kernel functionality? | Q: System calls cannot normally be made using standard function calls. What CPU mechanism is used by regular processes to invoke kernel functionality? | ||
Line 38: | Line 44: | ||
7) | 7) | ||
Q: After a fork system call, what runs first, the child process runs or the parent process? | Q: After a fork system call, what runs first, the child process runs or the parent process? | ||
A: Don't know... Undefined. Can not depend on ordering | A: Don't know... Undefined. Can not depend on ordering | ||
8) | 8) | ||
Q: Signal handlers can be called at almost any point in a process's execution. (T/F) | Q: Signal handlers can be called at almost any point in a process's execution. (T/F) | ||
Line 51: | Line 59: | ||
9) | 9) | ||
Q: System V init scripts run programs sequentially or in parallel? | Q: System V init scripts run programs sequentially or in parallel? | ||
Line 58: | Line 67: | ||
10) | 10) | ||
Q: Without errors, what does the execve system call return? # Who calls a signal handler? | Q: Without errors, what does the execve system call return? # Who calls a signal handler? | ||
Line 65: | Line 75: | ||
11) | 11) | ||
Q: What program is used to check the consistency of the data structures of a filesystem? | Q: What program is used to check the consistency of the data structures of a filesystem? | ||
Line 71: | Line 82: | ||
12) | 12) | ||
Q: What allocates the storage for environment variables and command-line arguments? | Q: What allocates the storage for environment variables and command-line arguments? | ||
Line 77: | Line 89: | ||
13) | 13) | ||
Q: A file that has a logical size of one gigabyte but only takes up 100K on disk is called what kind of file in UNIX? | Q: A file that has a logical size of one gigabyte but only takes up 100K on disk is called what kind of file in UNIX? | ||
Line 82: | Line 95: | ||
14) | 14) | ||
Q: What is an easy (but not foolproof way) way to tell that you are running in a virtual environment on Linux? What command do you run to get this information? | Q: What is an easy (but not foolproof way) way to tell that you are running in a virtual environment on Linux? What command do you run to get this information? | ||
Line 90: | Line 104: | ||
Not /dev/ because that's the abstraction. | Not /dev/ because that's the abstraction. | ||
15) | |||
Q:What is the purpose of the PATH environment variable? | Q:What is the purpose of the PATH environment variable? | ||
Line 98: | Line 112: | ||
16) | 16) | ||
Q: When would you expect ltrace to output more lines than strace? When should strace output more than ltrace? | Q: When would you expect ltrace to output more lines than strace? When should strace output more than ltrace? | ||
Line 106: | Line 121: | ||
17) | 17) | ||
Q: What command is used to change the priority of a process? | Q: What command is used to change the priority of a process? | ||
Line 116: | Line 132: | ||
18) | 18) | ||
Q: What is the difference between a library call and a function call? | Q: What is the difference between a library call and a function call? | ||
A: The former requires a library card and a telephone. | A: The former requires a library card and a telephone. |
Revision as of 18:46, 25 October 2012
Some answers to the practice questions 1)
Q: You can create a sparse file in UNIX by writing sequences of zeros to a file.
A: False. Sparse file means holes. Zeroes aren't holes. YOu need to move the file pointer. You have to use a seek. The data will be READ as zeros, though... Look up truncate command and strace it. It ain't just writing zeros
2)
Q: Are environment variables ``global variables? Specifically, if you change the value of an environment variable X in one process, what happens to the value of X in other processes?
A:Nothing happens. Env vars aren't globals. They're passed in with Execve. Environments variables are typically process specific.
3)
Q: In UNIX, there are three permissions associated with the user, the user's group, and everyone else. What are those three permissions?
A: rwx (Read, Write, Execute)
4)
Q: If you see a zombie process during normal system operation, how can you get rid of it?
A: Kill the parent Why? init will own the zombie process and then kill it
5)
Q: I can copy a file using I/O redirection as follows: cat /bin/ls > bar. If I now type ./bar, it won't run. However, if I run another command before typing ./bar, I will get a file listing. What needed to be changed to get bar to run?
A: chmod +x Default non executable. Need to make it executable. (--x)
6)
Q: System calls cannot normally be made using standard function calls. What CPU mechanism is used by regular processes to invoke kernel functionality?
A: Software interrupt
7)
Q: After a fork system call, what runs first, the child process runs or the parent process?
A: Don't know... Undefined. Can not depend on ordering
8)
Q: Signal handlers can be called at almost any point in a process's execution. (T/F)
A: True. That's the purpose of signals Register a normal C function as a signal handler Some are implemented by default (sigkill) Signals can be called at any point in execution.
9)
Q: System V init scripts run programs sequentially or in parallel?
A: Sequentially (sysV). Shell script that runs every command sequentially
Upstart does in in parrallel though...
10)
Q: Without errors, what does the execve system call return? # Who calls a signal handler?
A: execve DOES NOT RETURN ANYTHING. Process image is replaced.
The program itself calls the signal handler
11)
Q: What program is used to check the consistency of the data structures of a filesystem?
A: fsck <- wrapper function fsck.FMT <- called by fsck for a specific format (ex: fsck.ext4)
12)
Q: What allocates the storage for environment variables and command-line arguments?
A: The kernel. The kernel is the only thing that can allocate.(execve) This also makes sense because execve is a system call.
13)
Q: A file that has a logical size of one gigabyte but only takes up 100K on disk is called what kind of file in UNIX?
A: Sparse file.
14)
Q: What is an easy (but not foolproof way) way to tell that you are running in a virtual environment on Linux? What command do you run to get this information?
A: lspci, lshw. In /proc/, you may be able to also. These commands display the machine's "hardware".
Not /dev/ because that's the abstraction.
15)
Q:What is the purpose of the PATH environment variable?
A: At the command line, the $PATH variable is where the shell looks for binaries/files. The path is walked when the fullPATH/filename of the command line hasn't been specified
16)
Q: When would you expect ltrace to output more lines than strace? When should strace output more than ltrace?
A: Some libraries make no sys calls (strlen). Libraries that do basic string and math operations -> no sys calls
Programs with lots of I/O will use lot of sys calls
17)
Q: What command is used to change the priority of a process?
A: nice and renice nicess is policy value (default value and you can modify this) priority (dynamic) is based on niceness and the amount of time the process has run on cpu Priority doesn't apply to I/O. I/O will continue despite other processing having high priority. I/O will always slow down the system.
18)
Q: What is the difference between a library call and a function call?
A: The former requires a library card and a telephone.