<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Shahanahmed</id>
	<title>Soma-notes - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Shahanahmed"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/Shahanahmed"/>
	<updated>2026-05-19T00:22:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_2012_Week_11_Notes&amp;diff=17646</id>
		<title>COMP 3000 2012 Week 11 Notes</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_2012_Week_11_Notes&amp;diff=17646"/>
		<updated>2012-12-13T10:58:05Z</updated>

		<summary type="html">&lt;p&gt;Shahanahmed: /* Misc */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== CPU SCHEDULING ==&lt;br /&gt;
&lt;br /&gt;
* Kernel operations:&lt;br /&gt;
** switch to supervisor-&amp;gt; caused by interrupt&lt;br /&gt;
** when we switch back into user, we need to figure out what process to run next. THIS IS SCHEDULING&lt;br /&gt;
&lt;br /&gt;
* CPU state&lt;br /&gt;
** ready&lt;br /&gt;
** running&lt;br /&gt;
** loading (loading into memory)&lt;br /&gt;
** blocked (waiting for I/O)&lt;br /&gt;
** Scheduling takes processes and changes its state&lt;br /&gt;
** [http://en.wikipedia.org/wiki/Process_state see diagram] &lt;br /&gt;
&lt;br /&gt;
Which process does the scheduler run next?&lt;br /&gt;
* To avoid starvation, uses round robin algorithm&lt;br /&gt;
* preemption: max time a process can use the CPU&lt;br /&gt;
* prioritize unblocked processes: those using limited resources are prioritized&lt;br /&gt;
* priorities set by nice values and other jigging&lt;br /&gt;
&lt;br /&gt;
* Scheduling is HARD. Figuring out fine grained scheduling is still an open problem. Everything we have is a bit &amp;quot;hacky&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CFS (completely fair scheduler) is the linux scheduler&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I/O scheduling&lt;br /&gt;
* Disk scheduling.&lt;br /&gt;
** Elevator algorithm&lt;br /&gt;
*** &amp;quot;Get on elevator when it passes by, get off when it gets to your floor, but you&#039;re not controlling the elevator&lt;br /&gt;
*** there are exceptions though. Some processes &amp;quot;can control the elevator&amp;quot;&lt;br /&gt;
*** To avoid long &amp;quot;queues&amp;quot;, we batch I/O requests together (I/O reordering)&lt;br /&gt;
*** We employ HD caches to help deal with batching and I/O reordering&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Filesystems -- Journaled (revisted) ==&lt;br /&gt;
&lt;br /&gt;
FSCK walks the FS checking for errors. Takes long time. Bad idea. Journaled FSes fixes this.&lt;br /&gt;
&lt;br /&gt;
Journaled FSes&lt;br /&gt;
* Transactions do not happen directly to disk.&lt;br /&gt;
* We first write to a journal.&lt;br /&gt;
* Later, the journal will be read and the transactions will write to disk&lt;br /&gt;
* These transactions happen in a stream (sequentially), which will be much faster than random writes &lt;br /&gt;
* We&#039;re actually writing twice as much (time, transactions, not data) to the disk&lt;br /&gt;
* we actually write to the rest of the disk in the background, when nothing is relying on I/O&lt;br /&gt;
&lt;br /&gt;
* If you&#039;re writing a lot to your FS, though, this&#039;ll be slow. We&#039;re writing twice to disk. &lt;br /&gt;
** To solve this issue, convert the FS to a log structured FS.&lt;br /&gt;
** the entire file system becomes the FS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Log structured FS &lt;br /&gt;
* All data is added sequentially to the disk &lt;br /&gt;
* the actual log of additions becomes the FS, telling us where to find data on that disk  &lt;br /&gt;
&lt;br /&gt;
SSDs use wear leveling. Each memory cell has a dedicated lifespan. We try to lengthen their life by spreading the wear across the SSD.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Top ==&lt;br /&gt;
Top command.  Memory Types:&lt;br /&gt;
* virt- size of virtual address space - number of pages (doesn&#039;t typically matter)&lt;br /&gt;
* RES - how many frames in physical ram are taken up (should be smaller than virt)&lt;br /&gt;
* SHR - Shared memory between processes (shared frames amongst ALL processes)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Working set ==&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Working_set]&lt;br /&gt;
* Memory that you need for a certain task to make efficient progress. &lt;br /&gt;
* if you don&#039;t have enough space on the working set, your process will be spending alot of time writing and reading from disk&lt;br /&gt;
* there are many ways to manage the working set (page replacement)&lt;br /&gt;
* Optimal WS: The optimal working set is the one where you know ahead of time which pages you&#039;ll need to load into memory and those you won&#039;t. You&#039;re effetiively predicting the future&lt;br /&gt;
* LRU: least recently used (good for non streaming)&lt;br /&gt;
** Updating the last access time for every page would have alot of overhead, so we approximate this instead....&lt;br /&gt;
*** We can use the page table entry&#039;s metadata to help with this&lt;br /&gt;
*** Basic strategy: Clock algorithm. Sets zero to all page entry access metada every second. If we haven&#039;t accessed that page, the bit will still be zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Misc == &lt;br /&gt;
&lt;br /&gt;
Page replacement algorithm&lt;br /&gt;
*** If a page is not dirty and hasn&#039;t been accessed, kick it out&lt;br /&gt;
* &#039;&#039;&#039;Please Expand&#039;&#039;&#039;&lt;br /&gt;
* Dirty: If a page has data waiting to be written on disk, it is considered &#039;dirty&#039;&lt;br /&gt;
* Accessed: Some measure of the last time it was accessed, if it hasn&#039;t been accessed in a while (from the last sweep?) it is considered &#039;not accessed&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ubuntu&#039;s memory management is optimistic&lt;br /&gt;
&lt;br /&gt;
File caches&lt;br /&gt;
* write back caching: when writing to a file, a promise is made that we&#039;ve written the bits to disk, despite not having done.&lt;br /&gt;
* allows the coder not to worry.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Unified Page Cache&lt;br /&gt;
&#039;&#039;&#039; please expand &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TLB: Cachei of page table entries of working set of current process&lt;br /&gt;
Address space is page table&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Copy on write&lt;br /&gt;
* how forks are made&lt;br /&gt;
* after fork, parent and child share memory until memory is accessed &lt;br /&gt;
* share pages until write&lt;br /&gt;
* detect by marking all pages read only&lt;br /&gt;
* informally, it is making a shallow copy. It&#039;ll make a &amp;quot;deeper copy&amp;quot; when needed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fairness&lt;br /&gt;
* devoting resources to the programs you want is hard to implement&lt;/div&gt;</summary>
		<author><name>Shahanahmed</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_2012_Week_8_Notes&amp;diff=17542</id>
		<title>COMP 3000 2012 Week 8 Notes</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_2012_Week_8_Notes&amp;diff=17542"/>
		<updated>2012-10-31T17:24:06Z</updated>

		<summary type="html">&lt;p&gt;Shahanahmed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Practice questions and their associated answers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Q: You can create a sparse file in UNIX by writing sequences of zeros to a file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: False.  Sparse file means holes. Zeroes aren&#039;t holes.&lt;br /&gt;
You need to move the file pointer. You have to use a&lt;br /&gt;
seek. The data will be READ as zeros, though...&lt;br /&gt;
Look up truncate command and strace it. It ain&#039;t just writing zeros&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
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?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A:Nothing happens. Env vars aren&#039;t globals. They&#039;re passed in with Execve. Environments&lt;br /&gt;
variables are typically process specific.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Q: In UNIX, there are three permissions associated with the user, the user&#039;s group, and everyone else. What are those three permissions? &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: rwx (Read, Write, Execute)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Q: If you see a zombie process during normal system operation, how can you get rid of it?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: Kill the parent&lt;br /&gt;
Why? init will own the zombie process and then kill it&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Q: I can copy a file using I/O redirection as follows: cat /bin/ls &amp;gt; bar. If I now type ./bar, it won&#039;t run. However, if I run another command before typing ./bar, I will get &lt;br /&gt;
a file listing. What needed to be changed to get bar to run?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: chmod +x &lt;br /&gt;
Default non executable. Need to make it executable. (--x)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Q: System calls cannot normally be made using standard function calls. What CPU mechanism is used by regular processes to invoke kernel functionality?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: Software interrupt. Signals are a form of of software interrupt.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;A system call is an entry point into the Linux kernel. Usually, system calls are not invoked directly: instead, most system calls have corresponding C library wrapper functions which perform the steps required (e.g., trapping to kernel mode) in order to invoke the system call. Thus, making a system call looks the same as invoking a normal library function.&amp;quot; from man 2 intro &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;The call to the library function itself does not cause a switch to kernel mode (if the execution was not already in kernel mode) and is usually a normal subroutine call (using, for example, a &amp;quot;CALL&amp;quot; assembly instruction in some Instruction set architectures (ISAs)). The actual system call does transfer control to the kernel (and is more implementation-dependent and platform-dependent than the library call abstracting it). For example, in Unix-like  systems, &amp;quot;fork&amp;quot; and &amp;quot;execve&amp;quot; are C library functions that in turn execute instructions that invoke the &amp;quot;fork&amp;quot; and &amp;quot;execve&amp;quot; system calls. Making the system call directly in the application code is more complicated and may require embedded assembly code to be used (in C and C++) as well as knowledge of the low-level binary interface for the system call operation, which may be subject to change over time and thus not be part of the application binary interface; the library functions are meant to abstract this away.&amp;quot; from http://en.wikipedia.org/wiki/System_call&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q: After a fork system call, what runs first, the child process runs or the parent process?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: Don&#039;t know... Undefined. Can not depend on ordering&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Q: Signal handlers can be called at almost any point in a process&#039;s execution. (T/F)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: True. That&#039;s the purpose of signals&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Register a normal C function as a signal handler&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They every signal has a default signal handler defined in the C Standard Library.&amp;lt;br&amp;gt;&lt;br /&gt;
Most can be overwritten to have user-defined signal handlers, however some, (e.g. sigkill) cannot be overwritten. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Signals can be called at any point in execution.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;When a signal is sent, the operating system interrupts the target process&#039;s normal flow of execution. Execution can be &#039;&#039;&#039;interrupted during any non-atomic instruction.&#039;&#039;&#039; If the &#039;&#039;&#039;process has previously registered a signal handler, that routine is executed. Otherwise&#039;&#039;&#039; the default signal handler is executed.&amp;quot;  from http://en.wikipedia.org/wiki/Unix_signal&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q: System V init scripts run programs sequentially or in parallel?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: Sequentially (sysV). Shell script that runs every &#039;&#039;command&#039;&#039; sequentially&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Upstart does it in parallel though. This is the reason sysV is being replaced by Upstart. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q: Without errors, what does the execve system call return? # Who calls a signal handler?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: On success, execve() does not return, on error -1 is returned, and errno is set appropriately.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The program itself calls the signal handler&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q: What program is used to check the consistency of the data structures of a filesystem?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: fsck &amp;lt;- wrapper function&amp;lt;br&amp;gt;&lt;br /&gt;
fsck.FMT &amp;lt;- called by fsck for a specific format (ex: fsck.ext4)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q: What allocates the storage for environment variables and command-line arguments?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: The kernel. The kernel is the only thing that can allocate this space.(execve)&amp;lt;br&amp;gt;&lt;br /&gt;
This also makes sense because execve is a system call.&lt;br /&gt;
&lt;br /&gt;
Note that the kernel is the only thing that can change the size of a program&#039;s data segment directly (the wrapper for this system call is sbrk), but malloc is often implemented to call sbrk in advance, then divide up the space as malloc is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: Sparse file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: lspci, lshw.&amp;lt;br&amp;gt;&lt;br /&gt;
In /proc/, you may be able to also.&amp;lt;br&amp;gt;&lt;br /&gt;
These commands display the machine&#039;s &amp;quot;hardware&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Not /dev/ because that&#039;s the abstraction.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q:What is the purpose of the PATH environment variable?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: At the command line, the $PATH variable is where the shell looks for binaries/files.&lt;br /&gt;
The path is walked when the fullPATH/filename of the command line hasn&#039;t been specified &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q: When would you expect ltrace to output more lines than strace? When should strace output more than ltrace?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: Some libraries make no sys calls (strlen). Libraries that do basic string and math&lt;br /&gt;
operations -&amp;gt; no sys calls&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Programs with lots of I/O will use lot of sys calls&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q: What command is used to change the priority of a process? &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: nice and renice&amp;lt;br&amp;gt;&lt;br /&gt;
nicess is policy value (default value and you can modify this)&amp;lt;br&amp;gt;&lt;br /&gt;
priority (dynamic) is based on niceness and the amount of time the process has run on&lt;br /&gt;
cpu&amp;lt;br&amp;gt;&lt;br /&gt;
Priority doesn&#039;t apply to I/O. I/O will continue despite other processing having high&lt;br /&gt;
priority. I/O will always slow down the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Q: What is the difference between a library call and a function call?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A: The former requires a library card and a telephone.&lt;br /&gt;
&amp;lt;br&amp;gt; [[User:Spenner2|Spenner2]] ([[User talk:Spenner2|talk]])    nice&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shahanahmed</name></author>
	</entry>
</feed>