See how the COW finish the copy
About
The COW is Copy on Write,In my reading the Redis Database’s code process,i have had a problem:How redis to finish write in file when have other thread using the file?
Learning
Linux have some C function which namedfork()
and exec()
,for example,i will write some code to show how these function work.
1 |
|
now we use gcc
to build the out file and run it.
1 |
|
we can see the shell have double 1,we use gdb testing it.
1 |
|
in line six , GDB tell us the child process have been detach,we copied the parent process to the child process. After the content is output, the child process automatically disengages,untill finish the testing and remove the main process from the stack.
In this process, although our program have runing,the new process also be created, this is COW(copy on write),the child process(renamed B) copy the parent process(renamed A),if the system at this time still contains space, allocate a part to B so that B has enough resources to create child processes. if the space is insufficient, continue to use the resources of the parent process.
Is Redis,we need to make data persistent,But we couldn’t close the server, so we should use snapshotting , which is copy on write
Expend
except Copy on write,also have read on write(ROW)there are many similarities between the two. COW and ROW all used into snapshot technology