What happens to an open file handle on Linux if the pointed file gets moved or deleted

If the file is moved (in the same filesystem) or renamed, then the file handle remains open and can still be used to read and write the file. If the file is deleted, the file handle remains open and can still be used (This is not what some people expect). The file will not really … Read more

kernel stack and user space stack

What’s the difference between kernel stack and user stack ? In short, nothing – apart from using a different location in memory (and hence a different value for the stack pointer register), and usually different memory access protections. I.e. when executing in user mode, kernel memory (part of which is the kernel stack) will not … Read more

What’s the use of do while(0) when we define a macro? [duplicate]

You can follow it with a semicolon and make it look and act more like a function. It also works with if/else clauses properly then. Without the while(0), your code above would not work with if (doit) INIT_LIST_HEAD(x); else displayError(x); since the semicolon after the macro would “eat” the else clause, and the above wouldn’t … Read more

Writing programs to cope with I/O errors causing lost writes on Linux

fsync() returns -EIO if the kernel lost a write (Note: early part references older kernels; updated below to reflect modern kernels) It looks like async buffer write-out in end_buffer_async_write(…) failures set an -EIO flag on the failed dirty buffer page for the file: set_bit(AS_EIO, &page->mapping->flags); set_buffer_write_io_error(bh); clear_buffer_uptodate(bh); SetPageError(page); which is then detected by wait_on_page_writeback_range(…) as … Read more

What is the difference between the kernel space and the user space?

The really simplified answer is that the kernel runs in kernel space, and normal programs run in user space. User space is basically a form of sand-boxing — it restricts user programs so they can’t mess with memory (and other resources) owned by other programs or by the OS kernel. This limits (but usually doesn’t … Read more

What is ?= in Makefile

?= indicates to set the KDIR variable only if it’s not set/doesn’t have a value. For example: KDIR ?= “foo” KDIR ?= “bar” test: echo $(KDIR) Would print “foo” GNU manual: http://www.gnu.org/software/make/manual/html_node/Setting.html

Measure time in Linux – time vs clock vs getrusage vs clock_gettime vs gettimeofday vs timespec_get?

The problem is that there are several different time functions available in C and C++, and some of them vary in behavior between implementations. There are also a lot of half-answers floating around. Compiling a list of clock functions together with their properties would answer the question properly. For starts let’s ask what the relevant … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)