chapter 2 Flashcards
what is a virtual processor?
is a simulated processor built on top of the physical processor by the OS
what is a processor?
provides instructions along with the capability to execute them
what is a thread?
a single path of execution in a process. a process can contain multiple threads
what is a process?
a program in execution that can execute 1 or more threads
what are benefits of multithreading?
- hides network latencies [ program executes d/t thread when a thread blocks when ]
- resource sharing
what things is a process made up of?
- pid
- pc
- 1 executing program
- memory
- signal handlers
how is pid determined?
A process can determine:
- its own pid - pid_t getpid (void);
- pid of its parents - pid_t getppid (void);
how is pid determined?
A process can determine:
- its own pid - pid_t getpid (void);
- pid of its parents - pid_t getppid (void);
how is a process created?
only by another process
how can we differentiate between a parent and child process?
fork() returns:
- 0 to the child
- pid of child to parent
- -1 if error occurs
what does fork() do?
creates a child that is the exact copy of parent process, and hence executes the same program
what does exec() do?
allows a process to switch execution to a d/t program
when does a process stop?
- when the main() function returns
- when a program calls exit()
how can a process stop another process?
- by sending a signal to it
- SIGINT stops a process (ctrl + c)
what does a signal do?
notifies a process that a particular event has occurred
list some examples of signals.
SIG:
- SEGV - seg fault
- BUS - bus error
- PIPE - trying to write to a disconnected pipe
- CHLD - child process has stopped
- USR1, USR2 - generic signal used by user programs
why can’t processes influence eachother?
they are executed in isolation from each other
why can’t processes influence eachother?
they are executed in isolation from each other
in what ways can interprocess communications take place?
Through:
- semaphores
- pipes
- shared memory
- signaling
what is a pipe?
- a unidirectional communication channel between 2 processes.
- 1 can read from it and 1 can write to it
what type of processes can a pipe link?
those that share a parent since they’d inherit a file descriptor
what is shared memory?
- is an IPC technique that allows processes to access the same memory area.
how to use shared memory?
- create shared memory segment - shmget()
- attach process to segment - shmat()
- detach process from segment - shmdt()
- perform operations on seg - shmctl()
how do we create a shared memory seg?
int shmget (Key_t key, int size, int shmflg);
- key: will be used by children processes
- size: size in bytes of segment
- shmflg: access control mask
- returns: shmid if successful or -1 if not
how do we attach to a shared memory seg?
void *shmat (int shmid, const void *shmaddr, int shmflg);
- shmid - returned from shmget()
- shmaddr - specifies attaching address of seg, NULL if idc
- shmflg - access control mask
how do we detach from a shared memory seg?
int shmdt (const void *shmaddr);
- returns 0 in success -1 in failure
how do we destroy a shared memory seg?
int shmctl (int shmid, int cmd, struct shmid_ds *buf);
- cmd - command
- shared memory persist even after processes have died so they must be destroyed
why is multi-threading better than multi-processing?
- threads share processes’ memory, files, instruction & signal handlers
- a process can execute multiple threads
- thread communication is easier
- threads have their own id and pc
- threads have special synchronization primitives
what are standard unix threads in c?
posix ( p ) threads
how is multithreading done in c?
c has no built in multithreading support, so the OS has to provide this feature
how does a pthread stop?
- its process stops
- its parent thread stops
- its start function stops
- it calls pthread exit
what thread doesn’t stop even after its parent thread does?
detached thread
what synchronization concepts do pthreads use?
- mutex & condition variables
how does multithreading work in java?
- java has built in support for threading since threads are a native feature
to what are java threads mapped?
- to OS - native threads
- to user space - green threads
how is synchronization achieved in java threads?
- using monitors [ similar to mutex ]
- using conditional variables
how do conditional variables work in java threads?
- there are no explicit conditional vars in java, but we can explicitly block a thread
how do we explicitly block and unblock threads in java?
- wait () - current thread blocks
- notify () - wakes up a thread waiting on a monitor
- notifyAll () - wakes up all threads waiting
what is Goroutine?
is a light weight thread function that executes independently and simultaneously with other go routines in a program
what are concurrently executing activities in Go?
go routines
how are go routines managed?
by the go runtime
what is the r/n ship b/n go routines and shared memory?
- since go routines run in the same address space, shared memory must be synchronized.
compare and contrast between go routines and threads.
Go routines:
- have a faster startup
- have no id
- are cooperatively scheduled [ not preemptively ]
- have lower latencies
- are hardware independent
- managed by go runtime [ not the kernel ]
- have easier communication mediums
- have growable segment stacks
what is virtualization?
virtualization is the technique of creating external interfaces that abstract computer resources.
what are the roles of virtualization in DS?
- hardware changes faster than faster than software, hence SW can’t be maintained in the same pace as platforms it relies on.
- virtualization can solve this by porting SW to new platforms - virtualization creates ease of portability and code migration.
- virtualization isolates failing or attacked components.
what are the architectures of VMs?
- general instruction - interface b/n HW and SW, invoked by any program.
- privileged instruction - interface b/n HW and SW, invoked by privileged programs [ like the OS]
- system calls - interface b/n OS and library
- API - interface b/n library calls and application layer