Tag: linux

Notes on Memory Mapped Files using mmap

Introduction mmap maps a file to a process virtual address space. The file blocks are loaded as needed, in units of the system page size. Each I/O must align with the page size. A block load is handled as a page fault. mmap() can provide a private or shared mapping of a region. mmap() to allocate heap memory Interesting usage…

One Way Communication with Pipe in Linux

Pipe uses kernel buffer to store data. It is a unidirectional read/write buffer and connects two processes. Each end (read or write) Pipe mimics a file operation. A process can choose to read or write (but not both). The processes have to use at least two pipes for two-way communication. Example Communication Parent process can talk to a child with…

Why Docker is a Long Term Future for Platform?

What make Docker so popular and long-lasting? Container is essentially OS level virtualization. Each application gets illusion of its own OS, having almost absolute control over it. Another advantage is that host OS knows about the container processes and hence can share its resources among hosted containers. The concept of containers was started by FreeBSD, refined by Solaris and re-implemented…

Linux Memory Management Tricks

Tips to Improve Dynamic Memory Performance Instead of using memset() to initialize malloc()’ed memory, use calloc(). Because when you call memset(), VM system has to map the pages in to memory in order to zero initialize them. It’s very expensive and wasteful if you don’t intend to use the pages right away. calloc() reserves the needed address space but does…

Internet Not working eh? How Ubuntu Resolves DNS?

Problem I upgraded my Ubuntu from 16.04 to 18. And the Internet stopped working. 😦 I tried rebooting interface, adding a new interface to ifconfig. But it did not help. What helped was an answer on AskUbuntu How it worked? The answer is in how Ubuntu lookup domains like http://www.google.com. Step 1 Check the domain in the local DNS, also…

Internals of Linux Process Signals

Linux Signals A process in Linux is represented as task_struct. A process A sends a signal to process B using system call kill() or kill -<sig num> <pid>. Kernel updates the task_struct of the receiving process B. It changes the signal field with the passed value. The scheduler checks the signals on a process before running the process. If the…

Find a String in Files Excluding Some Files

— tags: ‘shell, linux, command, development, grep,find’ categories: development — I use the following command to find a string in a Go repo. The vendor directory is not needed, so skip it. $ find . -type f |grep -v vendor|cut -d”:” -f2|xargs grep -n my_search_string The command find all files in current directory. Next, it removes all files that have…

Fixing Terminal Row & Columns Display on Docker and Linux

Ever faced garbled screen on a terminal, text wrapping over and screen command string messed up! It happens because the terminal is using default row and column value (e.g. columns = 80). The following command fixes it (tested on Docker container’s terminal) docker exec -e COLUMNS=”`tput cols`” -e LINES=”`tput lines`” -ti How it Works? tput initializes or reset a terminal…