IPC Flashcards
What’s MultiProcessing?
Using several CPU cores (= processors) for running a single job to
solve a single “problem”
What threads don’t share?
Registers and stack.
What is the clone syscall?
Creates a new “child” process, similar to fork but gives more precise control over the creation.
What’s a pipe?
A pipe is a pair of two file descriptors (fd for short)
– int pipe_fd[2]
• Such that each integer is a handle to a kernel communication object
– pipe_fd[0] = read side of the communication channel
– pipe_fd[1] = write side of the communication channel
– Everything written via pipe_fd[1] can be read via pipe_fd[0]
What happens when a running process attempts to read through pipe_fd[0] but
nothing has been written yet via pipe_fd[1]?
the process will block
What happens upon writing to a pipe whose read end is close()d?
SIGPIPE (“broken pipe”)
What is the macro that provides safe system calling?
#define DO_SYS( syscall ) do { \ /* safely invoke a system call */ \ if( (syscall) == -1 ) { \ perror( #syscall ); \ exit(1); \ } \ } while( 0 )
Why do we need a sfae syscall invocation macro (with the do-while trick)?
why not just use an If?
Because then, code like this won’t compile */ if( condition ) DO_SYS( read(fd,buf,bufsiz) ); else printf(“can’t read()”)
Where DO_SYS is used as a statement
Why should read/write often be wrapped in a loop?
both syscalls return the
number of bytes they read/written
How communication is done in threads and how in processes?
Threads = communication is done via shared memory (more efficient and complicated) Processes = communication is done via explicit message passing (less efficient and complicated).
What’s Multitasking?
– Having multiple processes time slice on the same core
What’s Multiprogramming?
– Having multiple jobs in the system (either on the same core or on
different cores)