COMP 3000 2012 Week 8 Notes: Difference between revisions
postin' my answers |
Added question descriptions |
||
Line 1: | Line 1: | ||
Some answers to the practice questions | 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 | YOu need to move the file pointer. You have to use a | ||
seek. The data will be READ as zeros, though... | seek. The data will be READ as zeros, though... | ||
Line 7: | Line 9: | ||
2) | 2) | ||
Nothing happens. Env vars aren't globals. They're passed in with Execve. Environments | 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. | variables are typically process specific. | ||
3) | 3) | ||
rwx | 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) | 4) | ||
Kill the parent | 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 | Why? init will own the zombie process and then kill it | ||
5) | 5) | ||
chmod +x | 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) | Default non executable. Need to make it executable. (--x) | ||
6) | 6) | ||
Software interrupt | 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) | 7) | ||
Don't know... Undefined. Can not depend on ordering | 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) | 8) | ||
True. That's the purpose of signals | 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 | Register a normal C function as a signal handler | ||
Some are implemented by default (sigkill) | Some are implemented by default (sigkill) | ||
Line 34: | Line 43: | ||
9) | 9) | ||
Sequentially (sysV). Shell script that runs every ''command'' sequentially | 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... | Upstart does in in parrallel though... | ||
10) | 10) | ||
execve DOES NOT RETURN ANYTHING. Process image is replaced. | 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 | The program itself calls the signal handler | ||
11) | 11) | ||
fsck <- wrapper function | 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) | fsck.FMT <- called by fsck for a specific format (ex: fsck.ext4) | ||
12) | 12) | ||
The kernel. The kernel is the only thing that can allocate.(execve) | 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. | This also makes sense because execve is a system call. | ||
13) | 13) | ||
Sparse file. | 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) | 14) | ||
lspci, lshw. | 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. | In /proc/, you may be able to also. | ||
These commands display the machine's "hardware". | These commands display the machine's "hardware". | ||
Line 63: | Line 78: | ||
15) | 15) | ||
At the command line, the $PATH variable is where the shell looks for binaries/files. | 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 | The path is walked when the fullPATH/filename of the command line hasn't been specified | ||
16) | 16) | ||
Some libraries make no sys calls (strlen). Libraries that do basic string and math | 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 | operations -> no sys calls | ||
Line 73: | Line 90: | ||
17) | 17) | ||
nice and renice | 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) | 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 | priority (dynamic) is based on niceness and the amount of time the process has run on | ||
Line 81: | Line 99: | ||
18) | 18) | ||
The former requires a library card and a telephone. | Q: What is the difference between a library call and a function call? | ||
A: The former requires a library card and a telephone. |
Revision as of 18:44, 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.