COMP 3000 2012 Week 8 Notes: Difference between revisions

From Soma-notes
Manders (talk | contribs)
Added question descriptions
Manders (talk | contribs)
No edit summary
Line 10: 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?
A:Nothing happens. Env vars aren't globals. They're passed in with Execve. Environments
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.
Line 15: Line 16:
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?  
A: rwx (Read, Write, Execute)
A: rwx (Read, Write, Execute)


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?
A: Kill the parent
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)
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?
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  
A: chmod +x  
Default non executable. Need to make it executable. (--x)
Default non executable. Need to make it executable. (--x)
Line 29: Line 34:
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?
A: Software interrupt
A: Software interrupt


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)
A: True. That's the purpose of signals
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
Line 44: Line 52:
9)
9)
Q: System V init scripts run programs sequentially or in parallel?
Q: System V init scripts run programs sequentially or in parallel?
A: Sequentially (sysV). Shell script that runs every ''command'' sequentially
A: Sequentially (sysV). Shell script that runs every ''command'' sequentially


Line 50: Line 59:
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?
A: execve DOES NOT RETURN ANYTHING. Process image is replaced.
A: execve DOES NOT RETURN ANYTHING. Process image is replaced.


Line 56: Line 66:
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?
A: fsck <- wrapper function
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)
Line 61: Line 72:
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?
A: The kernel. The kernel is the only thing that can allocate.(execve)
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.
Line 66: Line 78:
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?
A: Sparse file.
A: Sparse file.


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?
A: lspci, lshw.
A: lspci, lshw.
In /proc/, you may be able to also.
In /proc/, you may be able to also.
Line 79: Line 93:
15)
15)
Q:What is the purpose of the PATH environment variable?
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.
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  
Line 84: Line 99:
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?
A: Some libraries make no sys calls (strlen). Libraries that do basic string and math
A: Some libraries make no sys calls (strlen). Libraries that do basic string and math
operations -> no sys calls
operations -> no sys calls
Line 91: Line 107:
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?  
A: nice and renice
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)
Line 100: Line 117:
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:45, 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.