Posts

Showing posts from March, 2018

IPC (Inter-Process Communication) on Linux

IPC 1.  Pipes 2.  Named pipes (also called as FIFO) 3.  Signals 4.  Message queue 5.  Shared memory 6.  Semaphores 7.  Sockets 1. Pipes:     Types:             a. Anonymous pipes             b. Named pipes OR FIFO     a. Anonymous pipes:         - Created b/w related processes         - Generally, parent ancestor create pipe and the fork child process. Each child process get access             to pipe.         - one end of pipe is read only and other is write only. This means pipe is half duplex.         - generally used to send data stream from one process to another (like | command in Linux)         - pipe is automatically deleted at the end of proccess         - Once data is read, cant be read aga...

What is condition wait and signal in multi-threading?

What is condition wait and signal in multi-threading? Explanation: When you want sleep a thread, condition variable can be used. In C under Linux, we have a function  pthread_cond_wait() to wait or sleep. On the other hand, we have a function pthread_cond_signal() to weak up sleeping or waiting thread. Threads can wait on a condition variable. Syntax of pthread_cond_wait(): int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex); Here,     cond : condition variable     mutex : is mutex lock Return Value: Upon successful completion, a value of zero shall be returned; otherwise, an error number shall be returned to indicate the error. The pthread_cond_wait() release a lock specified by mutex and wait on condition cond variable. Syntax of pthread_cond_signal(): int pthread_cond_signal(pthread_cond_t *cond); Here,     cond : condition variable Return Value: If successful, the pthread_cond_signal() functions...