Full emulation vs. full virtualization

Question: In full emulation the I/O devices, CPU, main memory are virtualized. The guest operating system would access virtual devices not physical devices. But what exactly is full virtualization? Is it the same as full emulation or something totally different?
Answer: Emulation and virtualization are related but not the same.
Emulation is using software to provide a different execution environment or architecture.  For example, you might have an Android emulator run on a Windows box.  The Windows box doesn't have the same processor that an Android device does so the emulator actually executes the Android application through software.
Virtualization is more about creating virtual barriers between multiple virtual environments running in the same physical environment.  The big difference is that the virtualized environment is the same architecture.  A virtualized application may provide virtualized devices that then get translated to physical devices and the virtualization host has control over which virtual machine has access to each device or portion of a device.  The actual execution is most often still executed natively though, not through software.  Therefore virtualization performance is usually much better than emulation.
There's also a separate concept of a Virtual Machine such as those that run Java, .NET, or Flash code.  They can vary from one implementation to the next and may include aspects of either emulation or virtualization or both.  For example, the JVM provides a mechanism to execute Java byte codes.  However, the JVM spec doesn't dictate that the byte codes must be executed by software or that they must be compiled to native code.  Each JVM can do it's own thing and in fact most JVMs do a combination of both using emulation where appropriate and using a JIT where appropriate (the Hotspot JIT I think is what it's called for Sun/Oracle's JVM).
Comment: @use736468, even if they don't show up 1:1 they can still be virtualized and not emulated.  For example, in VMWare you can have a virtualized CD drive which is connected to the real physical CD drive, or you can have an emulated CD drive that is backed by an ISO image on the host.  You're also running into an issue of theoretical vs actual differences.  Except for pure emulators like an Android emulator or those old 8-bit NES emulators (my favorite!), most produces will actually include some combination of both virtualization and emulation.
Comment: well in vmware a virtual guest would show the same cpu as the host but other devices are not the same as the host. So does it mean that the CPU is virtualized and other devices are emulated ?
Comment: I think this argument is a little circular.  For instance, it sounds like **Wine** is a virtualization platform for emulating Windows on Linux.  A hypervisor that uses CPU hardware to manage multiple OS's without para-virtualization is *virtualization*. A *GBA emulator* on a Windows PC is an *emulator*.  Everything else is probably a mix.  I think your comment is more to the point. +1 for trying the impossible.
Comment: You are saying that emulators emulate the CPU too, and virtualizers not so, but as user4 has pointed out,  Virtualbox or vmware mentions the CPU of the virtual machine, you can specify how many core it is.  So might that still be emulator a CPU?   If you say the emulated/virtual CPU has to be a different architecture for you to call it emulation, then the definitions sound rather arbitrary but additionally, i'd say what about dosbox, an emulator emulation an x86 CPU. The host may be an x86 CPU.
Answer:
A Hypervisor is a supervisor of supervisors i.e. it's the kernel that controls kernels.
Type 1 vs Type 2 vs Hybrid Hypervisors

A Type 1 hypervisor is an OS designed to run VMs. It is installed directly on the disk to be executed from the boot sector like any OS; it is an OS purpose built to manage and run VMs and that's all you can do on it (and like an OS, it can be monolithic or microkernelised). All OSs installed on it run as guests.
A Type 2 hypervisor is a hypervisor that runs on top of an OS that's designed to run applications, either as an application (full emulation), or by modifying the kernel with a driver to give the OS functionality to run VMs (virtualisation), which installs itself below/alongside the host OS invisibly, and the host OS continues to run (in ring 0 in the case of software virtualisation and non-VMX mode ring 0 in the case of the driver supporting hardware virtualisation) and the hypervisor that is hooked below it manages the guests in VMX non-root mode (in the case of hardware virtualisation) or ring 1 (in the case of software virtualisation) while passing off to the host OS where appropriate and calling into and using the host OS and its drivers to access hardware (which is why it is often pictured to be above the host OS). The GUI program on the host OS communicates with the driver and there is a subprocess per VM and thread per vCPU.
A Hybrid hypervisor is an OS that's designed to run applications and VMs. It can run in regular host OS mode but it has a hypervisor mode, which when booted into loads the host OS as a guest ontop of a hypervisor, and can load other guests. The hypervisor is typically a microkernelised hypervisor, meaning the hardware drivers are implemented in the host OS (called the parent partition) rather than the hypervisor (on Hyper-V, the Integration Services Components drivers can be installed on other guests to communicate with host OS drivers via the VMBUS system that the host OS sets up). The host OS runs in VMX non-root mode with a VMCS. Theoretically you could get a paravirtualised hybrid hypervisor but KVM and Hyper-V only support hardware virtualisation, furthermore, you could also have a monolithic hybrid hypervisor, but doesn't make much sense, and because of the presence of the host OS, it only needs to be microkernelised. A hybrid hypervisor is essentially a type 1 hypervisor that can boot into type 1 hypervisor mode and host OS mode separately. A microkernelised hypervisor is typically hybrid because the host OS used is the one already installed (and which the microkernelised hypervisor functionality is already part of -- it's available as a feature install on windows server)

Fully emulated Type 2 Hypervisors
A full emulator emulates all registers of the target ISA as variables and the CPU is completely emulated. This can be due to wanting to emulate a guest whose ISA is not the same ISA as the host (or indeed it can be the same if you run an x86 emulator e.g. Bochs and you happen to be running it on an x86 system; it doesn't matter. As Peter says, the emulator does not need privileged accesses (ring 0 driver helper), because all interpretation and emulation is done local to the process and the process calls regular host I/O functions. This works because none of the code needs to run natively. If you want it to run natively, you have to bring this functionality to ring 0 via a driver). Full emulation is an emulation of everything: the CPU, the chipset, the BIOS, devices, interrupts, page walk hardware, TLBs. The emulator process runs in ring 3 but this is not visible to the guest which sees emulated/virtual rings (0 and 3) which will be monitored by the interpreter and will emulate interrupts by assigning values to the register variables on violation based on the instruction it is interpreting, mimicking what the CPU would do at each stage but in software. The emulator reads an instruction from an address, analyses it and every time a register e.g. EDX comes up, it will read the EDX variable (emulated EDX). It mimicks the operation of the CPU, which is slow because there are multiple operations for a single operation that is usually handled transparently by the CPU. If the guest attempts to access a virtual address, the dynamic recompiler takes this guest virtual address and traverses the guest page table (mimicking a tlb miss page walker) using the vCR3 and then it reads directly from each physical address produced by vCR3+guest virtual address part using the emulator process page table whose cr3 it has no control over as it is a process and as far as the host OS is concerned the physical address is just a virtual address in the process (guest physical maps to a host virtual by adding an offset and then acting like a host virtual address, so an implicit P2M table). If the dynamic recompiler detects an invalid bit on the guest PTE as it traverses using vCR3 then it simulates a page fault to the guest putting the address in the vCR2.
Software Virtualised Type 2 Hypervisors
Full virtualisation, which is a type 1 hypervisor scheme, can actually be used on type 2 hypervisors and is a step up in performance from the former and can only be used if the guest ISA is the same as the host ISA. Full virtualisation cannot be achieved on x86 because:

There are certain flaws in the implementation of ring 1 in the x86 architecture that were never fixed. Certain instructions that should trap in ring 1 do not. This affects, for example, the LGDT/SGDT, LIDT/SIDT, or POPF/PUSHF instruction pairs. Whereas the "load" operation is privileged and can therefore be trapped, the "store" instruction always succeed. If the guest is allowed to execute these, it will see the true state of the CPU, not the virtualized state. The CPUID instruction also has the same problem.

Actually, this applies to ring 3 too. It's not just a glitch with ring 1. SGDT etc is not a privileged instruction, but allowing the VM to execute it contradicts Popek and Goldberg requirements because the VM can read the real state of the CPU and get the address of the real GDT rather than the virtual. Before UMIP, software full virtualisation was not possible on x86, and before Intel VT, x86 CPUs didn't inherently conform to Popek and Goldberg's requirements, so paravirtualisation had to be used. Paravirtualisation still does not conform to Popek and Goldberg (because only kernel mode code is patched, so SGDT can be used), but at least it works, whereas full virtualisation doesn't work at all, because SGDT will read a bogus value (the host SGDT) in guest kernel mode, meaning the guest kernel code using SGDT will not work as desired if it is not patched. SGDT being available in user mode at least doesn't compromise the host OS, whereas LGDT definitely would.
VirtualBox uses ring 1 full virtualisation, but paravirtualises the problematic instructions that act like they are executing in ring 0 despite being in ring 1, and requires the help of a ring 0 driver; the driver functions as the hypervisor. Surprisingly, there is very little information on how type 2 hypervisors are implemented. The following will be my best guess on the matter -- how I would implement a type 2 hypervisor given the hardware and host OS operation.
On Windows, I'd imagine when the driver starts it will initialise symbolic links and wait for the user mode virtualbox software to issue IOCTLs using DeviceIoControl to start a virtual machine instance. The handler will perform the following process: The driver injects a handler into the IDT for the general protection fault. It can do this by putting a wrapper around KiInterruptDispatch by replacing KiInterruptTemplate in the IDT with the wrapper. On windows, it could inject a wrapper into all IDT entries including entry bug check entries but this means hooking into the IDT write routines for new interrupts. What it probably does to achieve this is read the virtual address in IDTR and write protect the region and then host updates to the IDT will trap into the hypervisor GPF wrapper which will install a wrapper at the IDT entry written to.
However, a 64 bit windows guest on a 64 bit windows host needs to be able to have its own kernel space, but the problem is, it will be at exactly the same location as the host kernel structures. Therefore, the driver needs to wipe the whole kernel view of the virtualbox process. This cannot be mapped in or visible to the guest. It does this by removing the entries from the cr3 page of the virtualbox process. The GDT and IDT used by the virtualbox process and other host processes needs to be the same, but in order to avoid reserving guest virtual addresses, when the guest writes to the IDTR, the hypervisor could use this as the actual IDTR value, but virtually map it in the SPT to the same physical 4KiB IDT frame that the host uses. This means that the hypervisor driver needs to change the IDTR when switching between the guest and host threads. Because the guest virtual page that maps the IDT is write protected, any writes to this range by the guest will be logged by the hypervisor in a guest IDT that it builds if the cr3 is of one of its guests' processes. The issue is that when the ISR is handled, it will jump to a hypervisor RIP that is not mapped into the process because the driver lies in the host kernel; therefore, the RIP of this wrapper needs to be mapped into the SPT. This means you can't get away with reserving no virtual memory in the guest, and for that reason, you could probably get away with reserving the 4KiB address range the host uses for its IDT and silently redirecting guest accesses to a different host physical page and then not having to change the IDTR on a task switch. All reserved memory for the handlers in the host IDT would also have to be redirected silently to different host physical pages (because they will be supervisor pages so they will fault anyway and the hypervisor just redirects the reads and writes to a different host physical page, which won't happen after an interrupt because it will be in ring 0, so the jump in the IDT will be in the real host physical page mapped to it as it doesn't GPF so the hypervisor can't redirect), so the guest is unaware that that region is reserved. There will be a different wrapper for each IDT entry which will call a main handler which also needs to be mapped and pass an IDT entry code. The handler will pass the cr3 in a register, change the cr3 to a dummy process that maps the host kernel and then it will call the main handler. The handler checks the cr3 and if it is a guests shadow cr3 or host cr3 and perform the appropriate action.
The driver will also have to inject itself into the clock interrupt in the same way -- if the clock interrupt fires, the guest state or host state (which includes current cr3) is pushed and the hypervisor handler will push the address of the guest IDT clock interrupt onto the kernel stacks of all vCPU threads it manages (emulating what the CPU would do) in a new trap frame if there isn't one already present and then call the original host handler after changing the cr3 to one that maps the host kernel. This would ensure a context switch in the guest every time it is scheduled in on the host and therefore guest clock interval would roughly match up to host clock interval.
Full virtualisation would be referred to as 'trap and emulate', but it is not full emulation because all ring 3 code actually runs on the host CPU (as opposed to full emulation where the code that runs is the interpreter which fetches lines to read). Also, the TLBs and page walk hardware are actually used directly whereas on the emulator, every memory access requires a walk in software if not present in an emulated TLB array in software. Only the privileged instructions and registers, interrupts, devices and BIOS are emulated to the guest -- partial emulation -- emulation still occurs, but when any amount of the code runs natively, it becomes referred to as a virtualisation (full, para or hardware assisted).
When the guest traps into the guest OS it will either use INT 0x2e or syscall. The hypervisor obviously has injected a wrapper at 0x2e for INT and it will insert a handler at the SYSENTER_CS_MSR:SYSENTER_EIP_MSR for sysenter or IA32_LSTAR MSR for syscall. The handler in the MSR needs to be mapped into the SPT and will check to see if the cr3 is the shadow of one of the guest processes and if it isn't it doesn't need to change cr3 as the current will contain the host kernel and jumps to the host handler. If it is a cr3 of a guest process, it changes the cr3 to a dummy process (probably a virtualbox host process specifically for IO tasks that maps the host kernel) and jumps to a main handler, passing RIP in guest IDT that it has built to the recompiler/patcher which walks through and paravirtualises certain instructions that aren't guaranteed to trap, replacing them permanently with jumps to hypervisor memory where it places better code (which will cause protection faults as they're ring 0 in the SPT) until it reaches a IRET or sysexit etc and then it changes back the cr3 to that of the guest and executes an IRET after putting a ring 1 privilege on the stack to the RIP in the guest IDT it has built and then the actual guest ISR executes. When a trap occurs due to executing a ring 0 instruction in ring 1 or an inserted paravirtualised trap occurs, the ISR injected at the general protection fault entry / hypervisor ISR will make sure that the cr3 is of a guest process and it will claim and handle the issue, if it isn't then the cr3 doesn't need to be changed to one that includes host kernel in order to pass control to the host handler because it will be in the context of a non guest process. One instance where this could occur is the guest writing to cr3 for a guest context switch. This needs to be emulated as the guest must not be able to execute this instruction and modify the cr3 because it would change the cr3 of the host process on the host OS; the hypervisor needs to incept the write and write a new shadow cr3 and not the cr3 the guest wants. When the guest reads cr3, this mechanism prevents the guest from reading the real cr3 and the hypervisor inserts the value of the guest inserted cr3 (not the shadow one) into the requested register, inserts next instruction address onto the stack and resumes execution with an iret to the ring it was in.
Guest I/O will be targeted at a guest physical address space that maps onto virtual buffers and registers of emulated devices defined in the hypervisor. These emulated registers (e.g. doorbell registers) will be checked in a host context at regular intervals (clock interrupt hook for instance) in the exact same way a device would react to changes to hardware registers and the handler will decide whether an interrupt needs to be emulated (pushing an interrupt onto the kernel stack of the thread representing the selected vCPU to interrupt based on MSI vector assigned by guest in the emulated configuration space) or, due to an emulated register write, an I/O operation needs to be constructed using the Native windows API functions to the guest specified buffer (translating GVA->HPA and allowing real hardware to write to the physical page that the guest buffer will use).
As for paging on a paravirtualised 64 bit type 2 hypervisor, it is a tricky one. The hardware uses a shadow page table (SPT) which is a mapping of GVAs to HPAs. My best guess is that the hypervisor driver selects a shadow cr3 page from the locked pages of the virtualbox process for every GP fault (executing ring 0 instruction in ring 1) that it sees a new guest assigned cr3 address being written to cr3. It pairs this guest chosen address with the address of the hypervisor chosen shadow cr3 page and changes the virtualbox process cr3 to that of the shadow cr3 rather than the guest one that was attempted to be written. The shadow cr3 page (you'll see written everywhere that the guest page tables are write protected but it just has to be wrong because it is the shadow page tables that run on the CPU and therefore are the only ones that can cause protection faults; the shadow cr3 is used not the guest cr3) is write protected by the kernel driver (which is done by read/write bit in the recursive PML4 entry to itself). The cr3 page of certain GPA that the guest attempts to use will be translated to its associated HPA by the hypervisor and the entries in the cr3 page will be copied to the shadow cr3 and GPA addresses in the PML4Es will be translated to the HPAs using the P2M table. Every time the guest goes to write this to the guest cr3 page by virtual address, this virtual address will always be of the shadow cr3 page, not the guest cr3 page, and it will fault because of the write protect bit and being in ring 1. The handler injected at the general protection fault will then see a shadow cr3 of one of its guests processes and it will perform the write that was conceptually attempted in guest PTE, in the SPT at the same location (where it actually faulted), and it inserts the host physical address instead of the guest physical address that it tried to write (which it translates using the P2M TLB or P2M; I think the P2M is filled when you start the VM, because the VirtualBox process uses VirtualLock to lock the specified amount of RAM for the virtual machine) (the hypervisor can maintain virtual TLBs for the P2M (guest frame to host frame mappings) and guest page tables (guest virtual page to guest frame mappings), which it can check before performing software page walks, whereas the hardware maintains the TLBs for the SPT). Then the hypervisor will check the virtual TLBs for a quick translation of the CR2 GVA to a GPA; if not present it will trace the guest page table (by accessing the guest cr3 via its HVA (translates GPA->HPA using P2M and then HPA->HVA using a kernel function)) and write to the entry as the guest wanted with the attempted guest GPA. When a page fault occurs, the handler checks the shadow cr3 is one of its guest processes and checks the SPT (gets virtual address of entry associated with faulting GVA using Windows kernel function, as if it were a regular process) and then walks the guest page table using the guest cr3 associated with the current cr3, parsing the SPT virtual address that faulted (translates GPA -> HPA -> HVA). If the shadow PTE is invalid then it is a shadow page fault. If the guest PTE is invalid as well then it emulates an interrupt using the RIP of the address in the page fault entry of the guest IDT pushing it on the stack; before it does this it patches the code in the recompiler as described before (when guest reads from its page table during the interrupt, it will actually be reading the SPT and therefore the SPT needs to be read protected with a supervisor bit so it can be intercepted and the guest page table entry can be read instead from the address in the faulting memory access). For any other interrupt that occurs i.e. a host device, it is not meant for the guest and therefore if the handler sees the current cr3 belongs to a process of one of its guests it will change the cr3 to a dummy process that contains the host kernel mapping and calls the original KiInterruptTemplate for the host handler; after the host handler has finished, it will replace the cr3.
Hardware assisted Type 2 Hypervisors
Hardware assisted type 2 is a further step up in performance and makes the situation a lot less convoluted and unifies it into a single interface and automates lots of makeshift cr3 juggling and administrative tasks that needed to be improvised, making it a lot cleaner. The kernel driver only needs to execute vmxon, wait for guests to register with the driver and then all VM Exit events will be handled by a unified handler at a RIP and CR3 it inserts into the VMCS host state (meaning the handler stub does not need to be mapped in the guest kernel virtual address space). It is specifically designed for this, unlike ring 1, which means the recompiler (Code Scanning and Analysis Manager (CSAM) and the Patch Manager (PATM)) is not required. It also has things like TSC scaling and TSC offset fields which can be used by guests which employ the TSC for fairer scheduling. The hypervisor still hooks the clock interrupt to perform I/O updates and if the currently executing thread is the address of the thread for one of its vCPUs, it will need to vxmoff (which will cause a VM exit) and push the address of some reinitialisation sequence in host kernel memory that will vmxon and vmresume the VMCS tied to the vCPU with the guest saved state in it (but with an emulated clock interrupt in place ready to execute, whose code will use RDTSC which will VM exit and the offsets in VMCS can be used by the hypervisor to report a value accounting for time the guest wasn't scheduled in on the host, i.e. to subtract host time away from it to make the host invisible). It doesn't need to change the cr3 because the vmxoff does that automatically so now it can pass it to the host handler to perform the clock interrupt handing procedure for the host OS.
If EPT is supported, then the guest chosen physical addresses (cr3, IDTR etc.) and page tables run on the actual hardware in vmx non-root mode. GVAs are translated to HPAs as such: the guest CR3 is used to produce a GPA of the PDPT, which is then run through the whole EPT using the EPTP of the guest to eventually get the HPA of the PDPT, and so on (it's the same process as software virtualisation with the guest page table and the P2M, except the page walk is done on actual page walk hardware, which is faster). When there is a page fault, a vm exit does not occur and the guest chosen IDTR is present so the interrupt gets handled as a non root ring 0 using the guest IDT. The guest can update this mapping and the hypervisor doesn't need to intervene. When the access is reattempted, an EPT fault will cause a VM exit with the EPTP equivalent of cr2 and a pointer to the hypervisors EPTP for the guest. It will then update its mapping and VMRESUME to the RIP of the faulting instruction.
Answer:
In full emulation the I/O devices , CPU , main memory are virtualized.

No, they are emulated in software. Emulated means that their behavior is completely replicated in software.

But what exactly is full virtualization?

With virtualization, you try to run as much code as you can on the on hardware to speed up the process.
This is especially a problem with code that had to be run in kernel mode, as that could potentially change the global state of the host (machine the Hypervisor or VMM is running on) and thereby affect other virtual machines.
Comment: for clarification: http://www.computerworld.com/s/article/338993/Emulation_or_Virtualization_
Comment: From **ComputerWorld**: *Virtualization is a buzzword applied to many different technologies: servers, storage, communications, networks. An older, seemingly related term is emulation, but it's not the same thing. Here, we'll sort out the differences.*  If it is a *buzzword*, no one can answer this question definitely.
Comment: oh really. So emulation and virtualization are two different concepts ?
Answer: Without either emulation or virtualization, code runs directly on the hardware.  Its instructions are executed natively by the CPU, and its I/O accesses directly access the hardware.

Virtualization is when the guest code runs natively at least some of the time, and only traps to host code running outside the virtual-machine (e.g. a hypervisor) for privileged operations or I/O accesses.
To handle these traps (aka VM exits), the VM may actually emulate what the guest was trying to do.  E.g. the guest might be running a device driver for a simple network card, but the NIC is implemented purely in software in the VM.  If the VM used a pass-through to send the guest's I/O accesses to a real network card on the host, that would be virtualization of that hardware.  (Especially if it did it in a way that let multiple guest use it at once, otherwise it's really just giving it to one guest, not virtualizing it.)
Hardware support for virtualization (like Intel's and AMD's separate x86 virtualization extensions) can let the guest do things that would normally affect the whole machine, like modify the memory mappings in a page table.  So instead of triggering a VM exit and making the VM figure out what the guest was doing and then modifying things from the outside to achieve the result, the CPU just has an extra translation layer built in.  (See the linked wiki article for a much better but longer description of software-based virtualization vs. hardware-assisted virtualization.)

Pure emulation means that guest code never runs natively, and never sees the "real" hardware of the host.  An emulator doesn't need privileged access to the host.  (Some might want privileged access to the host for device pass-through, or for raw network sockets to let a guest look like it's really attached to the same network as the host).
An ARM emulator running on an x86 host always has to work this way, because the host hardware can't run ARM instructions in the first place.
But you can still emulate an x86 guest on an x86 host, for example.  The fact that the guest and host architectures match doesn't mean the emulator has to take advantage of that fact.

For example, BOCHS is an x86 PC emulator written in portable C++.  One of its main uses is for debugging bootloaders and OSes.
BOCHS doesn't care if it's running on an x86 host or not.  It's just a C++ program that reads binary files (disk images) and draws in a window (contents of guest video memory).  As far as the host is concerned, it's not particularly different from a JPG viewer or a game.
Some emulators use binary translation to JIT-compile the guest code into host code, but this is still emulation, not virtualization.  See http://wiki.osdev.org/Emulator_Comparison.
BOCHS is relatively slow, since it reads and decodes guest instructions directly, without doing binary translation.  But it tries to do this as efficiently as possible.  See How Bochs Works Under the Hood for some of the tricks it uses to efficiently keep track of the guest state.  Since emulation is the only option for running x86 software on non-x86 hardware, it's useful to have a high-performance emulator.  BOCHS has some very smart and experienced emulator developers working on it, notably Darek Mihocka, who has some interesting articles about optimizing emulation on his site.
Comment: I noticed that some of the boot loading code as simple as "  mov ax, [addr]"
 executing on vmware player behaves differently from real machine... do have good references (URL/research papers) explaining those differences?
Comment: @vtd-xml-author: The architecture is the same, the difference is the BIOS and how it sets up registers (including segment regs) before jumping to bootloader code.  See General Tips for Bootloader Development: https://stackoverflow.com/questions/32701854/boot-loader-doesnt-jump-to-kernel-code/32705076#32705076
Answer: This is an attempt to answer my own question.
System Virtualization : Understanding IO virtualization and role of hypervisor
Virtualization
Virtualization as a concept enables multiple/diverse applications to co-exist on the same underlying hardware without being aware of each other.
As an example, full blown operating systems such as Windows, Linux, Symbian etc along with their applications can coexist on the same platform. All computing resources are virtualized.
What this means is none of the aforesaid machines have access to physical resources. The only entity having access to physical resources is a program known as Virtual Machine Monitor (aka Hypervisor).
Now this is important. Please read and re-read carefully.
The hypervisor provides a virtualized environment to each of the machines above. Since these machines access NOT the physical hardware BUT virtualized hardware, they are known as Virtual Machines.
As an example, the Windows kernel may want to start a physical timer (System Resource). Assume that ther timer is memory mapped IO. The Windows kernel issues a series of Load/Store instructions on the Timer addresses. In a Non-Virtualized environment, these Load/Store would have resulted in programming of the timer hardware.
However in a virtualized environment, these Load/Store based accesses of physical resources will result in a trap/Fault. The trap is handled by the hypervisor. The Hypervisor knows that windows tried to program timer. The hypervisor maintains Timer data structures for each of the virtual machines. In this case, the hypervisor updates the timer data structure which it has created for Windows. It then programs the real timer. Any interrupt generated by the timer is handled by the hypervisor first. Data structures of virtual machines are updated and the latter's interrupt service routines are called.
To cut a long story short, Windows did everything that it would have done in a Non-Virtualized environment. In this case, its actions resulted in NOT the real system resource being updated, but virtual resources (The data structures above) getting updated.
Thus all virtual machines think they are accessing the underlying hardware; In reality unknown to them, all accesses to physical hardware is mediated through by the hypervisor.
Everything described above is full/classic virtualization. Most modern CPUs are unfit for classic virtualization. The trap/fault does not apply to all instructions. So the hypervisor is easily bypassed on modern devices.
Here is where para-virtualization comes into being. The sensitive instructions in the source code of virtual machines are replaced by a call to Hypervisor. The load/store snippet above may be replaced by a call such as
Hypervisor_Service(Timer Start, Windows, 10ms);

EMULATION
Emulation is a topic related to virtualization. Imagine a scenario where a program originally compiled for ARM is made to run on ATMEL CPU. The ATMEL CPU runs an Emulator program which interprets each ARM instruction and emulates necessary actions on ATMEL platform. Thus the Emulator provides a virtualized environment.
In this case, virtualization of system resources is NOT performed via trap and execute model.
Comment: Your still not correct.  A hypervisor can *map* hardware directly to an OS.  In your case, Symbian/Linux under a *hypervisor* can both have physical access to hardware.  However, **Access is under control of the HYPERVISOR**.  As a matter of fact, this is most efficient and the desired way to do this.  Symbian maybe able to access a radio and Linux a screen.  This access is granted by the *hypervisor* and that is *virtualization*.
Comment: If an OS can directly access hardware, it means that a physical machine is being accessed rather than a virtual machine. What you describe is some sort of partitioning of resources. I have always believed that all sensitive/control instructions (Load/Store on peripheral address space, CPU status word change etc) trap into hypervisor. Other instructions execute natively.
Comment: No, that is the in-efficient mode.  Normally the peripheral address are mapped to a guest OS.  The **mapping** is under control of the hyper-visor.  With many implementations, this is done with the **MMU**.  The *guest* OS can not setup an MMU; at least for para-virtualization.  A hypervisor does not emulate hardware (unless there is no other way) as that is extremely slow.
Answer: A more recent response:
From my research i can say that this is a better response to understand how concept appear:
The first concept of emulation actually dates back to the first computer, the Colossus. It was used by the British government in 1941 to mimic the functions of the Nazi Enigma code machine. Emulation theory was developed in 1962 and was conceived by three IBM engineers working from three different angles.
Emulation means to mimic the behavior of the target which can be hardware, like the emu8086 emulator, or can be software like emulation of a service from some network port.
You want to immitate the set of functions provided by the target and maybe you are not interested in the internal mechanism.
Why would you want that? For controlling that functions. Why control? For multiple reason which is very large subject to be discuss here. But keep in mind that you want to be behind the things.
But such process is costly for performance. You have an instruction for which are executed a lot of other instruction. Maybe you are interested to control only some of that instructions. So we would like to permit some of instructions to be executed native.
So what happens when all of this instructions execution became native? Then you have ideal virtualization.     You can virtualize any software, but the trend today is to pass from virtualization of operating systems to that of application. Also i say ideal because this software have a different execution on each hardware so it will be need to also emulate some instructions.Is important to understand that most of virtualize technologies from today are not only about virtualize, but also about emulation.
Also notice that in our transition from emulation to virtualization, the input which of system is reduced, because virtualization accept only software as input. The controller of these flow of instructions is named HyperVisor.
Answer: Virtualization may happen at different layers of a computer architecture, which are (from higher to lower): 1: Application, 2: Library, 3: Operating System, 4: Hardware Abstraction (HAL), 5: Instruction Set Architecture (ISA). Below the latter layer there is the Hardware.
Tipically a certain layer utilizes services from a lower layer by utilizing the instructions the lower layer exposes in its interface.
Note that the usage of service is not strictly related to the layering, in the sense that certain layers can skip the layer immediately below and utilize instruction from lower layers. As an example an Applications may provide certain instructions directly to the HAL layer, skipping the Library and O.S. layers.
To "emulate an instruction" means to intercept and map an instruction intended for a certain layer of a computer architecture (virtual) into a sequence (one or more) instruction(s) for the same layer of a different computer architecture (non-virtual).
It is possible to place the virtualization layer at different layers of a Computer Architecture. This point may introduce confusion.
As an example, when virtualizing at the level of the Hardware Abstraction Layer (e.g. VMware, VirtualBox), a virtual layer is placed between the HAL layer and the Operating system Layer. The Operating system utilizes instructions of the virtual HAL Layer, then certain virtual ISA (Instruction Set Architecture) are mapped by the hypervisor to ISA for the physical system. When ALL the instruction are emulated, we talk about full emulation, which is a special case of virtualization. In virtualization tipically we try to make a layer to execute directly instruction of the non-virtual layer as much as possible for performance reasons.
In another example, the virtualization layer is placed over the Operative System (Virtualization at Operative System Level): in this case a Virtual Machine is named Container (e.g. Docker). It includes the levels from Application to the O.S. (included).
To conclude, emulation is related to single instruction, while "full emulation" happens when we intercept and map ALL the instructions of a certain layer.
Tipically, the term "full emulation" is used when the virtualization layer is placed at the ISA level (lower level possible). In this case a Virtual Machine includes all the levels from the Application to the ISA, and ALL the ISA are intercepted and mapped. This is tipically used to virtualize niche products, such as Cisco routers (e.g. with QEMU) or 90's video game consoles, having a completely different architecture from the usual commonly available computers. Note however that there may be a "full emulation" also at other levels, which is tipically not necessary.
Answer: Virtualization and Emulation are pretty much the same thing. There is one underlying concept that these two words hint at. That is, these two words are aspects of one thing. This is demonstrated in QEMU, a Quick Emulator that performs hardware virtualization.
You can think of that one thing as Simulation. Simulation can also be a confusing word though.
First we can define the common meaning of the words.

Simulation: Making one thing do what another thing does.
Emulation: Making one system replicate another system exactly.
Virtualization: Allow for running of a system within another system.

Now we show that the words all mean pretty much the same thing. For example, in simulation you are creating a replica of one system with another system. That is the common meaning of emulation. In virtualization, you want to have your virtualized system act like the real system. That is, ideally it acts like a replica, even though it may be implemented differently and may not "emulate" the hardware exactly. That is the same as simulation pretty much. In an emulation, you simulate another system, etc..
So we can see that the words are somewhat interchangeable. The underlying concept is simulation.
In virtualization, such as operating system virtualization ("virtual machines"), we are creating a system which acts like the operating system. It might use tricks from the underlying hardware, or hypervisors, or other things, for performance and security. But in the end it is just a simulation of an operating system. Typically when the word "virtual machine" is used, it is not an exact replica of the machine (as in an emulator). It just does enough to allow programs to run as you would expect on the real operating system.
In emulation, it is typically meant that the simulation is "exact". In hardware emulation, you replicate all of the features of the hardware system. This means that you have created a simulation of the hardware. You could say that you created a virtualization of the hardware, but here is where virtualization slightly differs. Virtualization implies creating an isolated environment, which emulation doesn't necessarily imply. So a hardware emulator might provide the same interface to the hardware as the hardware itself, but the implementation of the emulator might rely on global memory, so if you try to run two emulators at the same time, they would interfere with each other. This is what virtualization solves, it isolates the simulations.
Hope that helps.
Answer: I think it's a common misconception to oppose Virtualization to Emulation when they're not comparable.
What people have in mind when they talk about Virtualization is mostly what type 2 hypervisors do.
According to wikipedia, virtualization is :

Virtualization or virtualisation (sometimes abbreviated
v12n, a numeronym) is the act of creating a virtual (rather than
actual) version of something, including virtual computer hardware
platforms, storage devices, and computer network resources.

This definition suits both emulation and type 2 hypervisor. Therefore, an Emulator is a subtype of virtualization, and Type 2 Hypervisor is another subtype. Both let you run a virtual machine, but the way they work and the way they're used often differ. Many virtual machines actually rely on both techniques to achieve their goal.
Moreover, emulation doesn't always replicate the original hardware 1:1 (by design and not by lack of documentation), such as DOSBox which simulates a kind of PC that doesn't really exist, or high level emulators (like the old Ultra HLE). This makes the emulator more efficient (but with the risk of breaking compatibilty with softwares). Other emulators also do this for a different purpose : to expand the capabilities of the original hardware (such as dolphin that let you run the game in 4K, or PS1 emulators that let you improve dramatically the quality of the 3D, or more recently, a SNES emulator with a modified PPU that can output 16:9 graphics and that's used for a modded super mario world patched to run in widescreen).
Some emulators can also use hardware ressources like a video card. An example of this is Connectix VirtualPC, an old PC emulator for PowerPC based macs. Back then macs and PCs both had PCI slots, and Connectix VirtualPC gave you the possibility to use a video card that was physically in your mac (which also existed on PC).
I hope this clarifies things.

Full emulation vs. full virtualization


Can I be an effective tanking Monk without a Shield at higher difficulty levels?

Question: I'm building a tanking Monk, however I have not yet found a shield worth using.
I find that the faster spirit generation caused by duel wielding (increased attack speed = faster spirit generation) is better than a little extra armor or chance to block < 1000 damage.
Since there really isn't a concept such as aggro, tanks need to be more than just damage soaks. They need to be able to control mobs, and keep them away from the squishier members of the party. To me, having faster spirit generation to control the mobs and keep them away from my allies seems more important than a little extra armor and block chance, providing my other gear provides me with enough stats to survive.
The best shields I've found so far have been about 1400 armor, and typically have < 20% chance to block a few thousand damage. The extra armor doesn't seem to be enough to be worth it, and the amount blocked seems too low to matter. If something is going to kill me, it hits for quite a bit more than 1k-2k.
But I am not sure if this will hold up in the higher difficulty levels.
Can I be an effective tank as a Monk without a Shield at higher difficulty levels?
It should probably be noted that I don't ever play my Monk alone, and this question is about being a tanking Monk as part of a group, not a tanking Monk playing solo (My current build is here)
Comment: This shouldn't be closed as a duplicate... I'm asking about the effectiveness of Shields vs Duel-Wielding for a Monk Tank (armor + block chance vs spirit regen), and not 2H vs Duel-Wielding (dps vs attack speed + extra attributes)
Comment: I don't have any high level monk experience, but the concensus I'm seeing has been exactly the opposite: that at high levels, 1H + Shield vastly outperforms the alternatives.
Comment: shield's 1400 armor is not small!! it is on average 20-30% of your TOTAL armor, that is HUGE!
shields with 25+ chance to block are common on the AH, so get them unless you for some reason (challenge) dont want to use AH.
also you should use justice lantern and helm of command, which will easily bump your block chance above 40%
Comment: @ŁukaszGruner I'm not saying the amount isn't decent, but I was trying to decide if the lost spirit generation from lower attack speed was worth the increase in armor and chance to block a bit of damage. So far, the answer has been no for me. The amount blocked is too low for me to make a significant difference, and the extra armor is not enough for me to lower my spirit generation and decrease my effectiveness as a tank :)
Comment: @Rachel after the last patch (aspd nerf) I ditched the shield, it is not worth it compared to aspd from dual wield.
Answer: Updated Answer
Having soloed inferno recently with a dual wielding setup on my monk, I can now say as a fact that dual wielding is absolutely possible.  But note, this highly depends on having two great weapons to use on your monk.
Here are the main advantages for dual wielding over a shield:

Additional socket on weapon for HUGE critical hit damage boost (This is the most important factor, I've severly underestimated how much DPS having more crit hit damage can provide with modest crit hit chance (~30%).)
A ton of more stats
More Life On Hit Proc (This is the second most important factor)
15% faster attack
15% more dodge

My primary weapon right now is a ~850 dps 250dex 250vit 500 life on hit axe.
My secondary is a ~750 dps 850 life on hit 97% critical hit chance axe.
The main goal of this setup is to have high dps with huge life on hit and high critical hit damage.  I'd prefer my primary to be socketed to have even more critical hit, but those weapons with similar stats to mine are too expensive right now and far beyond my reach.
Now that I have 3x more DPS than the old tank build, even though I'm down quite a bit on defense, its easier since I kill them faster so I don't have to tank as long.  Also, the really deadly effects such as arcane turret and ground effects can't be blocked anyway, making blocking less useful than killing the target faster.
Finally, dual wielding axes is major style points, imo looks much nicer than axe/shield ;)
Old Answer
This answer is still applicable since having 2 great weapons is really really expensive compared to 1 and a shield.
From my experience, a shield is extremely necessary in late game inferno and ponies (the 1.03 damage nerf has made shield even better by reducing the spikiness of damage).  Lets compare and contrast:
Shield Benefits

1000 - 1500 armor (double that if you use deadly reach)
70-140 resist all (70+ res all and another element of choice for stacking)
30-40% block (high block shield with JL + HoC) for 3k damage (note this is after reduction!)
1 free passive slot (you don't have to take guardian's path so you can devote 1 more passive for defense, such as resolve)

Overall, you gain HUGE damage reduction benefits for 1 equipment slot.  If you are trying to be a tank this is almost a no brainer.
Duel Wield Weapon Benefits

15% Faster attack speed for more LoH
More stats (weapons can get higher stats than armor can), and more unique effects like transcendence (having 100+ life per spirit spent is a great way to heal).
Faster spirit regen (even faster if you have 2 spirit regen weapons)
15% dodge (if you take the passive)

Overall, you gain a little dodge (doesn't work when frozen, etc, and you can't dodge ground effects like desecrate and plague, which are the main sources of death in late game inferno), some more potential sources of healing and spirit regen, more damage, but way less survivability.  Either way you won't be a tank.
To summarize, using a shield is a lot more defensive oriented, and thus provides the most survivability in late inferno acts (3+ and ponies).  Not to mention finding a good shield is a heck lot cheaper than finding a good 1 hander with high damage, ias, stats, and LoH.  You might be able to get away with duel wielding up to act 2, but I wouldn't expect you to last long beyond that unless you have godly gear and weapons.
Comment: I concur with your analysis.  Having a good weapon to switch out for a shield is viable for low level content (compared to your gear... for me Inferno Act 1).  But when you are trying to progress through difficult content, survival is more important and the defensive bonuses of shields far outweigh the increased spirit regeneration from dual wielding.  If I run Act 2 or 3 of Inferno, I need my shield.  -my personal experience
Answer: I personally think you can be, and I think you would be doing the monk an injustice by taking away a 2nd weapon and putting a shield in his hand. The monk is completely built around being a fast and hard hitting melee character. Even though Blizzard will let you equip a shield, could you ever see the character that Blizzard has shaped through the lore ever carrying a massive heavy shield around? I don't.
The concept of an avoidance based tank is perfectly viable, and I think by playing to the Monk's natural strengths you can be an excellent tank.
It starts with not only dual wielding weapons, but stacking attack speed increase. You need to make your spirit generators as fast as possible to keep a constant stream of spirit coming in so that your can continue using your spirit spenders to incap your enemies.
These are suggestions I might make based on the build you linked...
You might want to consider switching your primary attack. Crippling wave is awesome, and the movement speed decrease fits what you're trying to do well, but I might consider using Fists of Thunder + Quickening rune. A couple reasons...

The basic attack generates spirit quicker than any other primary
attack as per the tooltip.
Adding the Quickening rune gives you an instant 15 spirit boost each
time your crit.
The movement speed gimp that crippling wave applies can easily be
offset by a cyclone strike + blinding flash combo which results in
total incapacitation, rather than just a speed decrease.

The second move I would make it a passive skill change. Since spirit generation should no longer be an issue, I would drop "Chant of Resonance" in favor of "The Guardian's Path" to get the extra 15% dodge. This will help your survivability immensely in the middle of those large packs, and I think you will have plenty of spirit with your primary attack + dual wield change.
Gear wise, seek out the attack speed increases as well as life on hit, life on kill, etc. Also, find a good spirit stone that puts a lot of item points into spirit regen.
Otherwise, I think you are definitely on the right path, and think your build as is is viable. I just wanted to offer up a different approach.
Comment: I've started using some of your suggestions (more attack speed, life-on-hit, a good spirit stone, and a different passive than `Chant of Resonance`), and so far I'm finding it is definitely possible to be a duel-wielding tank at higher difficulty levels. I am finished with Hell, and am currently in Act II of Inferno. I tried a shield a few times, but always find I survive better duel-wielding. I tried  out `Fists of Thunder` and don't like it compared to `Crippling Wave`, and use `One with Everything` instead of `Guardians Path`, but overall thanks for the advice and words of encouragement :)
Answer: I'm also in Hell mode now, and I always play with at least one friend, but usually 2 or 3 friends.
Many of those friends run very high dps builds, so it offsets my low dps allowing me to stack more defense and use my crowd control abilities.
I run with a shield, but I am also experimenting with duel wield and 2 handed play.  For me the shield is very solid at the moment because it carries a large amount of Resist all, Vitality and dex, plus the block stat and the 1k armor.
Shield vs No Shield
Shield:  Block value aside it's very hard to pass up 1k armor, 30 resist all and 60 vitality. That's all hard mitigation that affects every kind of hit I take whether i'm cc'd or not.
No Shield: You'll gain DPS,  increased attack speed thus more spirit during attacks, more Dodge, and can have decent Vit for life on an offhand.
Dodge - The issue Dodge though is that it isn't hard mitigation.  If you are CC'd then you don't dodge at all. After you burn serenity and eat a second Frozen, that's going to hurt, especially if you don't have Pacifism 75% Damage reduction when CC'd
Spirit - Now here is where things get tricky.  'Tanking' isn't about standing in front of the mobs and soaking up damage in this game.  Later Hell and inferno show that you just cant.  Sure you can tank trash mobs, but who cares about them.  Can you tank that Molten, Frozen, Arcane pack?
So controlling that pack becomes your priority.  Keeping them contained so that your dps'ers can safely apply their dps without becoming zerged and 2 shot.
Thankfully your CC abilities don't cost that much spirit for the most part, but your other support abilities do and you aren't going to be standing in among that Firechains/shielded/arcane pack for very long my friend to get hits on them to gather spirit.
So bottom line is, if you can't stand toe to toe and tank the mob packs that are actually going to threaten your group, then what good is all that previously discussed mitigation?  Having 'some' is important of course, to take a couple of hits at least while getting close, but suddenly 'spirit regen' becomes really important so that you can keep firing off your abilities to help your group!
This opens the door for looking for gear with spirit regen mods.  A nice 2 handed weapon with spirit regen, The Guardians Path for regen, Air Ally with it's chance to regen 100 spirit, healing mantra with Circular breathing, etc   all become very viable options.
Spirit regen so you can continue to control the kiting for your friends could be the way to go.
Of course as I said,  I'm also only in early hell, so this is all theorycrafting for me at the moment.  Great topic though and glad I found this discussion.

Tin
Comment: Do you have a reference stating that you cannot dodge while being stunned? I was under the impression that you can.
Answer: I think shield is a far better choice.  Not mentioned is that shields can have up to 10% crit hit chance on them.  Depending on how good your weapons are, you may actually gain dps by using a shield.
If you can get your crit chance above 20% (a 10% shield does half that for you) and use Sweeping Wind Cyclone, you will watch monsters melt.
Comment: Thanks, however I'm definitely not a dps character, and usually don't try to be. I'm more concerned with the tanking/survivability aspect of using a shield
Answer: I have a monk myself lvl 51 I was duel wielding up until lvl 50 when he'll was just ripping me apart. I switched to a shield today and I must say it is a huge improvement. The key is finding a shield with dexterity. With the shield I have equipped I only lost about 20 DPS an gained over 1200 defense and 4000 vitality. I have no problem dealing with crowded areas as I thought would occur. I do play both public and solo and in both I am able to provide needed mantras to my party and disperse large groups for my fellow players. I have found a happy medium with my shield that allows me to continue being a quick handed attacker (losing only .04 attack speed) while not having to concern myself with losing health to rapidly. You must find the gear that fits your build to be able to enjoy the best of both.
Answer: Im hoping your using Mantra of Healing to help your survivability tanking as a Monk. However, all the posts I read say put the Sustenance Glyph on it for extra healing. The way I see it, the Mantra of Healing is more important for getting your health up between fights and not that important when fighitng an elite who can smack you around and cause massive damage fast. I like to use this as an oppurtunity to get some spirit regeneration by using the Circular Breathing Glyph instead. This way, you can build up spirit fast. As far as the shield versus non-shield, its a good question. Im built for tanking and find that I almost always have full spirit and because all my skills are for tanking, I barely blow through my spirit. Maybe thats a result of the fact that I dual wield and build spirit fast, or maybe thats a reason that I should use a shield as I barely use all my spirit. I figure ill find out more in Inferno.
Comment: This answer could have been left as a comment, but it could be improved to provide some additional information regarding the question at hand.  First, your "Answer" to the question is hidden, try to highlight that because that is what people are looking for.
Answer: Avoid Mantra of Healing, with a target 60k+ health, it does absolutely peanuts. Use the damage up mantra, with the rune that gives chance to heal on hit. With very high attack speed and fists of thunder (total of 5 punches) this provides 1500-2000 heal per completion. This means that in those moments when you're safe (whether it is by blinding flash, free moment from arcane/molten, or actual invlunerability) you will be healed. Stack life leech on that as increased damage as well. Monks are not sitting rocks, and are only effective offensively - get that DPS up. 40k or so for act III Inferno is good.
I'd have to say shields vs. double fisting may be fairly equal if you have unlimited money to spend. Otherwise there aren't really that many great secondary fist options, and the added DPS is fairly minimal if you hold the dex on shield/other weapon as equal. Blocking takes away damage done, and the added defense does help. More importantly resistances are crucial to surviving Inferno and shields can offer a lot of it.
Use elective mode (enable under the game options) to allow you to use more useful skills for the right mouse button.
Comment: The structure of your answer could be significantly improved.  Currently, your opening paragraph has little-to-no relevance towards the question.  It could more appropriately be left as a comment.


How to prove that this function is integrable on $[0,1]$

Question:
Here I tried to find two step functions, one of them is less than $f$ on $[0,1]$ whereas one of them is greater than $f$ on the same closed interval, to prove this function is Riemann-integrable on this interval, however, I could not find such two step functions to help me show this function is integrable. May I get some hint about the solution to this problem?
Comment: What does the symbol $[1/x]$ mean?
Comment: @Antoine It has been used to denote greatest integer function in my book and lecture notes so far.
Comment: Fix $\varepsilon > 0$. Choose $n$ such that $\frac{1}{n} < \frac{\varepsilon}{2}$. Consider the partition $0, \frac{1}{n}, \frac{1}{n-1}, \frac{1}{n-2},\dotsc, \frac{1}{3}, \frac{1}{2}, \frac{1}{1}$.
Comment: @DanielFischer You should write this hint as an answer.
Comment: Please do not use pictures for critical portions of your post. Pictures cannot be searched and are inaccessible to those using screen readers.
Comment: You are right. I could not squeeze two rows in that big bracket, then decided to put picture.
Comment: @DanielFischer could you please continue a a bit more?
Answer: Hint:
$$\int_0^1 (-1)^{[1/x]} \, dx = \lim_{n \to \infty}\sum_{k=1}^n\int_{1/(k+1)}^{1/k} (-1)^{[1/x]} dx = \lim_{n \to \infty}\sum_{k=1}^n\int_{1/(k+1)}^{1/k} (-1)^k dx \\ = \sum_{k=1}^{\infty} (-1)^k \left[\frac1{k}-\frac1{k+1} \right]=\sum_{k=1}^{\infty}  \frac{(-1)^k}{k(k+1)}$$
Alternatively consider a partition $P = (0, 1/n, \ldots, 1/2, 1)$.
The difference between upper and lower Riemann sums is $1/n$ since
$$\sup_{(1/(k+1),1/k]} f(x) - \inf_{(1/(k+1),1/k]} f(x) = (-1)^k - (-1)^k = 0,$$
and
$$\sup_{[0,1/n]} f(x) - \inf_{[0,1/n]} f(x) = 1.$$
By choosing $n$ sufficiently large, this difference can be made smaller than any $\epsilon > 0$ and $f$ is Riemann integrable.
Comment: I am sorry but in the book writer did not mention relation between lim and integral operator.
Comment: Yes I know, in calculus course it is treated so but in analysis course we just learned epsilon and step functions definition and I have to proceed in that way on this example.
Comment: Ok then follow @Daniel Fischer's suggestion.  I'll finish this to show how you evaluate the integral, in case you are interested.
Comment: Please, continue to answer :)
Answer: I think if you use $\dfrac{1}{k+1}\leq{x}\leq{\dfrac{1}{k}}$ and cover interval $[0,1]$. Then it shows that discountinuty of $f$ is in countable point.
Answer: First try to sketch the graph.
Denote the upper and the lower Riemann sums for a partition $P$ of a function $f$ by $U(P,f)$ and $L(P,f)$ respectively.
We say that $f$ is Riemann integrable if for any $\varepsilon >0$ there is a partition $P$ such that $$\big| U(P,f)-L(P,f)\big|< \varepsilon$$
Observe that the upper and the lower sums are always equal for a constant function.
Pick $\varepsilon >0$. There is a natural number $N$ such that $\frac 2 {N} < \varepsilon$
Consider the partition $0 < \frac 1 N < \frac 1 {N-1} < \frac 1 {N -2} < \cdots < 1$
Now since $f$ is constant on $( \frac 1 2 , 1]$ and $( \frac 1 3, \frac 1 2 ]$ and $\dots$ and $( \frac 1 N,\frac 1 {N-1}]$, upper and lower sums will be equal in these intervals.
Also, $f$ is bounded above by $1$ and below by $-1$ gives that
$$\big| U(P,f) - L(P,f) \big| \leq \bigg| \big(1 \cdot \frac 1 N + \text{ some other terms} \big) - \big( -1 \cdot \frac 1 N + \text{ some other terms} \big) \bigg| = \frac 2 N < \varepsilon$$
Many steps are missing in the proof above.
Comment: Why is there plus sign after $ -1 \cdot \frac 1 N$?
Comment: Would you mind answering @ThePortakal ?
Comment: Ooops, sorry. I fell asleep. What I meant there was $U(P,f) = 1 \cdot \frac 1 N + something$ and $L(P,f) = -1 \cdot \frac 1 N + something$ and so that when you subtract $L(P,f)$ from $U(P,f)$ the "something" terms will cancel each other.
Comment: The thing that I did not understand is if there should be minus sign before second $something$ or not?
Comment: No. It is fine the way it is above.
Comment: I will have a look and try to get again.


Best way to fix IAT and relocs when patching (merging) two different binaries (x86 PE)?

Question: First of - Hello and thank you for reading this,
I have one DLL which I do not have the source code but need to add some functionalities into it.
I made up another DLL implementing all these needed functionalities in C - using Visual Studio.
Now I need to insert the generated code from this new DLL into the target DLL (it has to be done at the file level {not at runtime}).
I am probably creating a new PE section on the target DLL and put there all the code/data/rdata from the dll I made up. The problem is that I need somehow to fix the IAT and the relocs relative to this new inserted code on the target DLL.
My question is:
What is the best way to do it?
It would be nice if Visual Studio came up with an option to build using only (mostly) relative addressing - This would save me a lot when dealing with the relocs.
I guess I could encapsulate all my vars and constants into a struct, hopefully MSVC would then only need to relocate the address of this "container" struct and use relative addressing to access its members. But don't know if this is a good idea.
I could even go further and get rid of the IAT by making a function pointer which would dynamically load the needed function module (kind of the Delay Load Module). And again, put this function pointer inside the "container" struct I said before.
The last option I have is to make it all by hand, manually editing the binary in hex... which I really didn`t want to do, because it would take some good time to do it for every single IAT entry and reloc entry. I have already written a PE file encryptor some time ago so I know most of the inner workings and know it can be done, just want to know your thoughts and maybe a tool already exists to help me out?
Any suggestions is highly appreciated!
Thanks again for your time for reading this!
Answer: Since you are asking for suggestions, take a look at the very good PORTABLE EXECUTABLE FILE FORMAT – A REVERSE ENGINEER VIEW PDF Document. The Section "Adding Code to a PE File" describes some techniques (and presents Tools) to add code to an existing PE image without having the code of the target image (your scenario) by manipulation the IAT table and Sections tables.
Comment: Thank you for replying.
That helped a lot about the IAT, but still didn't find a good way to deal with the relocs, guess I am going to have to write a small tool to automate the fix!


Is there an opportunity in PHPStorm the same abbreviation of Live Template to be expanded in different ways by tab and enter?

Question: For example I want abbreviation php to be expanded in two ways:
1) With Tab:
<?php $END$ ?>
2) With Enter:
<?php
  $END$
?>
I can't create the same abbreviation in one group.
I can create template with abbreviation php expanding with tab in one group and another template with the same abbreviation expanding with enter in another group.
But the problem is that when i print php and press Tab I get this: the list of two snippets.
e.g the second snipped assignes to Enter also expands by Tab.
Is there an opportunity in PHPStorm the same abbreviation of Live Template to be expanded in different ways by tab and enter without any menus like this?
Thanks.
Answer: No, it's not possible. IDEA-67811 asks for a way to assign shortcuts to individual live templates, please feel free to vote for it


2D Animation Rendered View is green

Question: Alot of the 2D ANimation tutorials I'm watching apply this sick Rim Effect that creates a cast shadow/highlight on the desired objects (Grease pencil strokes), however, I can't see it being applied. If I go to rendered view, I can see the modifiers and effects are working however, everything turns Green! Please help!
Blender file (4.4mb) is here: https://pasteall.org/blend/81b468f8fd21484ea2ca7985bfce8c4f
Cycles and Evee have the same issue (GPU compute, CPU makes no difference)
World Colour is white, surface set to background
My rig:
Intel Xeon E3 1270 3.30Ghz
18 GB Ram
MSI RX 570 4GB
Answer: Materials have been overridden by vertex color
Open Vertex Paint edit mode, then Paint -> Reset Vertex Color

2D Animation Rendered View is green


GTA 5 email problem

Question: I forgot what email I used for my Grand Theft Auto 5 account on PC, and now I wonder how I can check it out. I have tried looking it up inside the game, but it does not find anything.
Answer: There are some things you can try:

See if you're still logged in on Rockstar's website in any of the browsers you use.
See if you have a password vault in one of your browsers that saved that account information for you.
Contact Rockstar support. Create a new account if necessary.
Log into any of your email accounts you think you might have registered with and search for emails containing 'Rockstar' or 'Social Club'.
Depending on the service you use or bought the game from, there might be options there to recover the email address you used.
Try logging in to other Rockstar games you have, to see if that Social Club account is the same as the one you use in GTA V.
Try 'brute-forcing' your way in with all the email addresses you have. This might take a while, but also teach you to remember or write down your account information :)

GTA 5 email problem


If only the Sith deal in absolutes, why does Obi-Wan say it that way?

Question: Obi-Wan tells Anakin that "Only the Sith deal in absolutes", and uses that as his identification that Anakin had actually turned to the Dark Side.
But it would seem the statement itself "Only the Sith deal in absolutes" would be an absolute statement itself, and that his rash actions based on this single statement is just as 'Sith-like' as Anakin's statement of "Either you're with me or against me" (paraphrased, I forget the exact statement.)
Is this not a very clear indicator that the Dark Side is present in all who use the force, and reinforces Palpatine's assertion that the Jedi are simply blind to the powers of the dark Side instead embracing their full potential?
Comment: Obviously, Obi-Wan is a secret Sith.
Comment: This is the same kind of spurious circular logic that a lot of right-wingers use when they say "Your intolerance of my intolerance shows that your message of tolerance is hypocritical!" to which the correct answer is "Well spotted, clever boy, now have a cookie and go away while the adults are talking."
Comment: Wouldn't Yoda's "Do or do not, there is no try" be an absolute statement?
Comment: Obi-Wan was [the most awesome of the Sith](http://www.psu.com/Leaked--Dark-Obiwan-character-art-for-Battlefront-III--a006156-p0.php)!
Comment: "A Jedi will never make predictions, padawan."
Comment: Yes, it is.  Absolutely!
Comment: I think you can say absolutely that the script is pretty bad at that point.
Comment: @Shadur, the logic is **not** circular, but yes that's a good example of Obi-Wan's unwitting hypocrisy. Though I'm not sure how cookies fix hypocrisy. If so, feel free to post that as an answer.
Comment: @Shadur, ah I now understand you. http://have-a-cookie.urbanup.com/4530054#.VUOUjPt-4hQ
Comment: Yes, only one philosophy is prone to that, you're so right...
Comment: @PaulDraper Here, have a cookie.
Comment: I feel like it works because Obi-Wan is making an observation as opposed to an imperative. If he said, "All Jawas have bright yellow eyes", or "All Wookies are hairy" (or whatever), that's an absolute statement, but does that make him a Sith? Doesn't he also mention to Luke about how Jedi's use light sabers and that blasters aren't refined enough for them? He doesn't deal with polarizing opposites and you have to choose between them as your only options. At least that's what I thought he meant.
Comment: Congratulations Corsika on your new Great Question badge.
Comment: I'm pretty sure that Obi-Wan's statement is hyperbole unless he literally claims that no sapient non-Sith being in the universe deals in absolutes, not even on occasion. On the other hand, Anakin's statement is, supposedly, given the circumstances, meant as a literal ultimatum – that Obi-Wan rejects because he is loyal to his principles above specific people.
Answer: Out-of-universe, this is a pot of message situation - Lucas wanted to connect the Sith to statements that President Bush had made that Lucas presumably regarded as insufficiently nuanced. It's a real clunker of a line, given that it's truly the Jedi who view the world in Manichean "Light side / Dark side" terms. But that's hardly the only clunker in the movie.
"Anakin, you're breaking my heart" comes to mind...
Nevertheless, I think the line can be interpreted to make a little sense...Obi-Wan merely expressed himself a little clumsily (can you blame him, giving the circumstances?). One can imagine the following, more elegant exchange:

Anakin: In the circumstances surrounding loyalty, fealty and overall
  alignment of purpose and action, one is either of entirely one mind
  with the person so referred to by the practice of the perpendicular
  pronoun, or one must be said to be in a state colloquially referred to
  as being "at odds". Any state of matters which can be said to be as
  falling within these two extremes is so insufficiently asseverative as
  to be fundamentally and wholly indistinguishable from opposition.
Obi-Wan: Individuals or persons not counting themselves among the
  number of those who refer to themselves as "the Sith", would be
  hard-pressed to make a statement as utterly categorical, and not
  admitting, upon mature reflection, of views which, at the end of the
  day, would have to be said to be more balanced (in an, of course,
  non-epistemological fashion) and, frankly, more sophisticated.
Comment: Amazing! Your dialog would actually make the film *worse*. :)
Comment: I just finished my first draft...it's 40,000 pages long.
Comment: I suppose that your proposed "more elegant exchange" between Anakin and Obi-Wan occurs in a mansion's library, both sitting, drinking cognac, and smoking pipes (don't forget the tiger rug).
Comment: There was a great British comedy series, "Yes, Minister", that specialized in this kind of humor. Some of the phrases and definitely the general tenor of it are lifted directly from some of the filibustery speeches that one of the characters regularly delivers.
Comment: On bad lines, I liked Anakin's "I don't like sand. It's coarse and rough and irritating and it gets everywhere" zinger from *Attack of the Clones*. Deep stuff, Anakin.
Comment: Chicks like being compared to "not sand"...unless they are named Sandy.
Comment: @ChrisB.Behrens: Are you a lawyer? That was some dry stuff!
Comment: Your dialog now has [serious competition](http://scifi.stackexchange.com/questions/87536/why-does-the-batmobile-have-a-no-step-sign#comment192547_87546).
Comment: You should really include Anakin's response to Obi-Wan's little monologue there: "Say WHAT?!?!?" :-)
Comment: @Oldcat - I hear that line being delivered by Hugh Laurie as Dr. House.
Comment: I suspect the same motive applied to the "bring balance to the force" prophecy, where "bring balance" meant "utterly annihilate the side we don't like."  Lucas viewed "balance" as more sophisticated or such, but still wanted the good guys to win.
Comment: It's a Spoonerism coined by Theodore Sturgeon, off of the Biblical allusion.
Comment: Is there evidence that this text line was added to the script after J W Bush said it?
Comment: @Pierre - that might be worth its own question. That has always been my strong presumption, but I don't know for sure.
Comment: It's _"mess of pottage"_, not "pot of message", lol.
Comment: @MatemáticosChibchas Yes, but one of them is on a slightly elevated platform.
Answer: I hear this a lot, and have even made fun of it myself. BUT, I sometimes think folks aren't slowing down enough to consider what was actually said:

First, what was NOT said. Obi Wan did NOT say, "There are no absolutes." And, he did NOT say only a Sith believes in absolutes.
Second, what he DOES say is "Only a Sith DEALS in absolutes." Dealing in absolutes has more to do with the unilateral nature of the correspondence. Once you make unilateral proposals, you aren't negotiating, you aren't even really "dealing" at all. Instead, you're dominating the other party/person.
Third, think of the context. Anakin is saying things like you're either with him or against him. Not, "let me hear what you think" or "give me your perspective on this matter." He's dealing in an absolute manner.

It's not a contradiction to say Only a Sith deals in absolutes. Making an absolute statement such as "There are no absolutes" would, however, be a contradiction.
Hope that's helpful.
Comment: Actually, it was Obi Wan who first tried to talk Anakin out of what he was doing and thinking. He tried to reason with him first.
Comment: As well as trying to talk him out of it before sabers were ignited, it was Anakin who charged Obi-Wan. You think the master of Soresu would strike first?
Comment: Considering Obi Wan attacked Anakin immediately after uttering those words, I would say he's dealing in absolutes too.
Comment: I'm glad this answer hasn't been retconned out yet. It's quite good.
Comment: This is the correct answer to this. It's pretty absurd how Obi-Wan's line has held up as a meme, he said "deals in absolutes" he didn't say absolutist things don't exist or that the Jedi don't ever embrace them or anything remotely of that nature.

 And I mean for crying out loud, 1+1=2 is an absolutist statement. There is no scenario where 1+1 does not equal 2 or where 1+1 is more or less than 2. A whole lot of English speakers are bad at understanding plain English lol.
Comment: Great answer, exactly the sort of philosophical treatment it needed.
Answer: That scene was actually there to express how Obi-wan was a hypocrite.
When Palpatine had told Yoda that his arrogance had blinded him, this was true, and was the reason why Yoda afterward had been struck by a concentrated blast of Force Lightning.
This shows how the Jedi and Sith in some ways had become very similar, without the Jedi Masters taking notice.
It is paralleled, when Obi-wan, telling Anakin "only a Sith deals in absolutes" reveals himself as a hypocrite, likely unknowingly.
Again, another subtle theme packed into the story.
Comment: Everyone deals in absolutes throughout the saga -

- Luke: "That's not true! That's IMPOSSIBLE!"

- Han: "NEVER tell me the odds"

- Leia: "Help me, Obi Wan - you're my ONLY hope"

- Admiral Ackbar: "We have NO CHOICE, General Calrissian! Our cruisers CAN'T repel firepower of that magnitude!"

- Mace Windu: "Protect the senator at ALL costs."

- Qui Gon Jinn: "There's ALWAYS a bigger fish."

- Chewie: "Rrraaarrrgghh"
Comment: I kinda like this answer, but I don't think this is the message that Lucas wanted to convey.
Comment: I feel like you are giving Lucas to much credit by giving it subtle undertones that weren't intended. Although I like your explanation.
Comment: @Wad Cheber - And don't forget Leia's "Darth Vader. Only you could be so bold." If people understand Leia didn't literally mean no one in the galaxy but Darth Vader would be bold enough to invade her ship, I don't see why it's any harder to believe Obi-Wan wasn't using "only" literally, but meant something more along the lines of "the Sith have an extremely pronounced tendency to deal in absolutes, which the Jedi try to avoid".
Comment: I agree with your opinion, but it's not likely that's what george lucas meant. But yes, it's the Jedi that deal in absolutes the whole saga
Comment: I think that's exactly the point of the story. Sith vs Jedi, endless cycle, right or wrong, greater good or freedom. Cycle again.
Comment: In Drew Karpyshyn's Darth Bane trilogy, set centuries earlier, the Sith and Jedi were even more alike, especially in the beginning before Bane instated (or reinstated) the Rule of Two, after killing off the other Sith.
Comment: @Wad Cheber  Not all absolute statements are the same.  Some absolutes are based on faith some are based on facts and some are based on faulty reasoning. The example you used  "We have NO CHOICE, General Calrissian! Our cruisers CAN'T repel firepower of that magnitude!"   that statement is based on facts. Anakin made a statement that was based on facts. He was using black & white reasoning he was using faulty logic.  He created a false dilemma.. That is what Obi-Wan meant by dealing in absolutes
Answer: I think that the word being overlooked here is "deals". It is one thing to make an absolute statement. It is another to make one that refers to a fight. The words "deals in" refers to how Anakin thought he had to fight Obi-wan. It was a battle deal. The only reason Obi-wan fought Anakin was because Anakin was attacking. So... to expand Obi-wan's dialogue, he was meaning, "Only a Sith will engage in combat due to absolute reasoning."
It makes sense now because Obi-wan was not making any absolute statement that was dealing in combat. He made an absolute statement but it was not one that made his conscious have to fight Anakin.
Of course, there are bound to be mistakes all throughout the Star Wars dialogue. We like to try to make sense of things, but in reality the things people say on Earth are often filled with error. People make mistakes, and this shines through even in movies. After all, movies are made by people.
Comment: "It makes sense now" - well I don't know about that, but I do really like your line of reasoning here! I also disagree that there are bound to be mistakes 'all throughout'. There was no budget for this movie that wouldn't have been approved, and there are probably about 20 million (for lack of a better term) Star Wars geeks who would have done it for free in order to make a canonically sound movie.
Answer: It's a fairly common fallacy. Who here hasn't heard "Nothing is black and white."? Many people are unaware of the inherent inconsistency of the statement. While many things are to some extent gray areas, a statement ruling out absolutes is itself absolute!
He probably meant something more along the lines of:

The Sith often make the naive mistake of simplifying a situation into black-and-white more than is reasonable. You're making a mistake consistent with the ideologies of our enemies. Can't you see how you've been fooled into working for the other side?

Importantly, that line was from the RotS. It's a well-accepted part of the SW universe that one of the reasons that the original trilogy was better was that Lucas wasn't so famous that you couldn't talk him out of his sillier ideas. By the time the prequel trilogy rolled around, he was much too big a person to say no to.
Comment: Zebras are black and white.
Comment: Damn, you caught me.
Comment: And the fact that the statement "nothing is black and white" when taken *literally* espouses a logical fallacy does in no way detract from the fact that it's a very true statement.
Comment: Shadur, what are you on about? It's both logically *and* empirically false. There are clear examples of objective fact, of evil and good in the world.
Comment: There is no fallacy, he did not say absolutes don't exist. He said only the Sith deal in absolutes. Clearly referring to the Jedi and the Sith. As a Jedi he did not regard Anakin as his enemy that he needed to fight to the death, he tried to bring him back to the good side. It was Anakin who drew the line and declared Obi-Wan an enemy. Exact phrasing matters lmao.
Answer: I was struck by this line as well when I first heard it in the movie, as not very many lines of that caliber (as in thought-provoking) appear in the "newer" movies. This is a line written in the film to show how far Anakin had really gone. Obi-wan was really the only Jedi at the end who still supported Anakin, and still listened to him when he was angry about being rejected from the title of Jedi Master. The council had for the most part distanced themselves from him.
If you think about it, the Sith are portrayed for the most part as cold-blooded, robotic beings, fueled only by their desire for power, power and more power. The line referring to Anakin's new vision of everything as black and white meant he was losing touch with his human feelings and therefore reality. Cold hard logic: if I join Palpatine, I will be able to prevent Padme's death, regardless of anything else that might happen because of this!
This is further evidenced in the fight between the two Jedi, Obi-wan and Anakin where Obi-wan states:

"I have the high-ground Anakin"-Obiwan "you have no idea how powerful I have become!"-Anakin

At which point he, meaning Anakin, loses many of his appendages.
Darth Vader had become so heartless that he did not even calculate the danger of his body being injured by attacking at point.
And anyways, what if I said everything I have said is a lie?
Answer: In my opinion Obi-Wan used that line when he finally realized, that he can't talk down Anakin back to jedi way.
To me it was more like a quote, as if Obi-Wan quoted some ancient statement as last hope to get understanding of the situation into Anakin's head. I mean like we on Earth sometime use "The die has been cast" or similar statements and everyone in room knows what it means because its part of our history, as that statement could be part of history of the Jedi order. But this is just speculation.
Answer: Obi-Wan says it this way for several reasons: primarily, he and Anakin are at the end of their long relationship and this is one final attempt at reason, but it also is a specific response to a specific extreme statement from Anakin.
Recall their exchange:

Anakin: "If you're not with me, then you're my enemy."
Obi-Wan: "Only a Sith deals in absolutes."

Anakin's statement is an absolute statement, betrays Anakin's Jedi training, betrays the long relationship of mentoring and friendship established by Obi-Wan with Anakin, and serves as the symbolic completion of Anakin's fall to the Dark Side of the Force and becoming a Sith. All of that aside, at this point, the two are still talking, and there remains a slight chance for Obi-Wan to wake Anakin to the wrongness of his beliefs and actions.
Obi-Wan's reply, put this way, "Only a Sith deals in absolutes," then is intended to convey several things:
First, that Anakin's comment was an absolute statement, one antithetical to Jedi Way.
Next, that it was absolutely wrong with regard to Anakin's assessment of Obi-Wan and Anakin's relationship; Obi-Wan can clearly love Anakin and remain his friend while disagreeing that siding with Palpatine and murdering Jedi younglings is a correct action to take.
Finally, Obi-Wan is intending to convey he knows Anakin is a Sith, and hopes Anakin realizes this.
Obi-Wan's statement is not intended to theorize about a universal law; he is aware there might have been or may be Sith who deal in things other than absolutes. Rather, he replied in this way to try to save Anakin from further falling to the Sith ways.
Answer: Yes it makes Obi-Wan a sith, that is why they had to fight. There can only be two sith at a time, and since Palpatine was on another planet, the only solution was to strike Anakin down to restore balance to the force. A good Jedi like Obi-Wan is able to understand the importance of keeping the force in balance, even if it means embracing elements of the dark side while retaining his sense of justice, and without losing his perception of good and evil.
Comment: Congratulations on not having received more down-votes, so far.
Comment: best answer I've ever seen on stack overflow
Comment: This is one of those deeper answers that sees something almost certainly unintended. I like it!


Will apt-get dist-upgrade blow away my PostgreSQL server setup?

Question: I'm about to upgrade my webserver, my site relies heavily on PostgreSQL database and settings.  I started apt-get dist-upgrade, and it says it wants to upgrade Postgres.  I cancelled, but will it wipe out my database and settings?  I know, "backup" and I have, but I still prefer not to set it up again if I can avoid it.
Comment: Make sure you understand the difference between `apt-get dist-upgrade` and upgrading from one version of Ubuntu to another, they are not the same thing.
Answer: No, it shouldn't overwrite any databases. As for the settings, the new package may have updated settings files (eg. for a new default value or a completely new setting) but it should always ask you for a confirmation about overwriting the settings. That dialogue will also have an option to compare the new and old settings file and an option to keep the old settings. Since you have a backup, it is safe to install the update.
Answer: It will not wipe out your database or settings.
But there is a chance that you will run into Debian bug #714725, which will cause your old server package to be uninstalled, leaving you unable to access your data.  For example, if you now have postgresql-8.4 installed and the upgrade proposes to install postgresql-9.1, the old 8.4 instance should just keep on running.  But it's possible that apt-get dist-upgrade decides to uninstall the postgresql-8.4 package, which wouldn't be good.  So be sure to read the output of apt-get dist-upgrade about what it proposes to do.  If you don't like what it proposes to remove, run something like apt-get install postgresql-8.4 to mark the package(s) as manually installed.


Ephemeral network interfaces

Question: I'm on Ubuntu 20.04 and each other time when I access a web page, Chrome says "Your connection was interrupted ERR_NETWORK_CHANGED".
Running watch -n.1 ifconfig shows my cable, wireless and loopback interfaces and an additional interface named vethRandomSuffix. This interface always disappears from ifconfig output when its TX packets reaches 20, then another vethRandomSuffix appears.
Example veth interface:
veth9f101b1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::e0b1:cff:fe00:aa24  prefixlen 64  scopeid 0x20<link>
        ether e2:b1:0c:00:aa:24  txqueuelen 0  (Ethernet)
        RX packets 3  bytes 126 (126.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14  bytes 1954 (1.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Before I observed this problem, I had many veth interfaces created by VirtualBox, so I uninstalled VirtualBox and then removed all the veth interfaces using this answer: https://superuser.com/a/1307218.
I would appreciate if someone could tell me a way to find what process keeps bringing these interfaces up and down.
Answer: As it turns out, Docker also creates interfaces named vethRandomSuffix.
I must had brought down one of Docker interfaces when I cleaned them.
My solution was restarting docker service
sudo service docker restart.

Ephemeral network interfaces


User account on iMac won't allow applications to open

Question: When my friend logs into his user account and tries to open the Mail App, he just gets the spinning ball and it won't open. Safari and other apps will open, but they take forever. When his wife or kids log in under their accounts, the machine is as fast as ever.
I had him repair permissions and verify the disc. Both processes went fine, but did not help.
It's a 5 year old iMac with 4 gig of Ram running the latest version of Yosemite.
Any ideas?
Comment: Any unusual activity noted in the Activity Monitor? (Found under Applications > Utilities)
Answer: One big change since El Capitan - Mail is now in V3
All the rest will be the same.
Try clearing the saved state, rebuilding & reindexing the database...
Clear Saved State

Switch to Finder,  Cmd ⌘   N  for a new window, then  Cmd ⌘   Shift ⇧   G  for Go To...
copy/paste ~/Library/Saved Application State/com.apple.mail.savedState then  Enter ⌅
This is an alias to the real location, so Right-click & Show Original
Delete the entire com.apple.mail.savedState folder.

Rebuild; Re-index
Source: How to fix Apple Mail by rebuilding and reindexing the Mailbox

Step 1: Rebuild
  Rebuilding a Mailbox in Mail sounds daunting but it really isn't.

Launch Mail, select one of your mailboxes and click on the Mailbox menu. At the bottom of the pane choose the Rebuild option. If you have a large mailbox, you can expect the process to take a few hours.
You must repeat this step for each one of your Mailboxes.
While the process takes place, you may experience system performance lag, as it can consume a lot of system resources and memory.

Another caveat, if you use IMAP or Exchange with any of the accounts, the process will redownload every message from the server, so you'll use a lot of bandwidth.
Now that you've completed these steps, work with Mail a little longer. If you are still having issues, or Mail fails to launch, you should try a manual reindex.
Step 2: Re-index
Manual reindexing of Mail messages is the only way to go if the  application has become so unresponsive it barely works at all, search is not functioning correctly or the app won't launch.
Mail will automatically attempt to reindex your messages if it detects problems with the mailboxes, but sometimes a manual reindex is the best option. If you are still having problems with Mail after following step one, try manual reindexing.

Quit Mail if it's open.
  To get to your home Library folder, hold down the Option key, then in the Finder choose Go > Library.
In ~/Library/Mail/V2/MailData, delete any file that begins with "Envelope Index," such as Envelope Index or Envelope Index-shm. (Before you actually delete the files, it makes sense to copy them to a folder on your desktop.)
Launch Mail and the app will build new Envelope Index files -- this can take a long time if there are numerous messages to go through.
If everything seems to be working correctly, you can now delete the copies of the "Envelope Index" files from your desktop.

In most cases, these two tips should solve most Mail problems


How can I replace all \r\n with \n using Komodo Edit

Question: Somehow, some 40 files (mostly Python modules) in my project have \r\n (Windows style) as line endings. I'd like to change them to \n (Unix style) line endings, but Komodo Edit doesn't appear to provide a way change existing files' line endings, and a simple regexp find and replace using Komodo doesn't work either.
Answer: There is actually a built-in feature for this in Komodo, but it's hard to find.
Right-click the Edit tab select Current File Settings. Under File Settings, change "Line Endings" to UNIX (\n) and de-select "Preserve existing line endings".
This is fine for individual files, but it would be a bit of a hassle if you were trying to do several files as a batch. For that, you could wrap some of swatso33's suggestions into a saved command using interpolation shortcuts.
UPDATE (2014-10-13): There is now an option: Clean Line Endings under the Code tab.
Comment: Excellent, thanks. I ended up spendin 20 minutes last night changing them by doing open file -> copy contents -> command w -> close and delete file -> command shift t (which prompts to recreate the file) -> paste contents -> save. I got each one down to about 8 seconds by the end lol, but wasted time early on doing extra steps.
Answer: You can do this with either perl or sed using:
 perl -pe 's/\r?\n|\r/\r\n/g' inputfile > outputfile  # Convert to DOS.
 perl -pe 's/\r?\n|\r/\n/g'   inputfile > outputfile  # Convert to UNIX.
 sed -e 's/$/\r/' inputfile > outputfile              # UNIX to DOS  (adding CRs on Linux based OS that use GNU extensions).
 sed -e 's/\r$//' inputfile > outputfile              # DOS  to UNIX (removing CRs on Linux based OS that use GNU extensions).
 perl -pe 's/\r?\n|\r/\r/g'   inputfile > outputfile  # Convert to old Mac.

Code snippet is from http://en.wikipedia.org/wiki/Newline#Conversion_utilities
Answer: At http://bugs.activestate.com/show_bug.cgi?id=93976 I give a macro
that changes the line-end setting and the actual line-endings when a
file that is under Git SCC is opened in Komodo.
You can also modify that macro to quickly update all loaded files.
Answer: With Komodo[edit], one can control replacements of CR manually using regular expressions replacement tool. Same goes for most popular editors. This used to work great with np++.
Here is the way to go with Komodo:

Fill in Find input with \r

Then make sure to switch on BOTH following options
"Treat the pattern as a regular expression" (No need explanation)
"Use Multiple Lines"  (Search will treat file content as a whole and not line by line. As a consequence pattern will match any characters until it fails, including CR, LF, etc. )