Wednesday 25 December 2013

Programmer should know about memory

Hereby am sharing some of points about modern memory architecture

- Intel Hyper-threading enabled single processor core to be used for two or more concurrent executions with just little extra hardware

how exec system call works

Interesting implementation of parallel file upload and do socket polling 

Scenario  you need to look for the incoming data, and do ftp file upload. 

From C program you can invoke exec system call to do ftp file upload 

For FTP  either you can use CURL library  / linux / some other libraries .  I recommend CURL, i've been working on this quite a time.

Lets say:  I've a process  created thread in it ,doing socket select operations , 
               when i receive some X message i need to do file upload. 

Better approach: 

From your packet handler thread , spawn process  obliviously do "fork" , let child process do ftp file upload, parent wait for child to complete file upload. 

After file upload child process exited, followed by process detached . 

Here there is no interruption with packet handler routine, since both packet handling and ftp file upload runs in different process context .. so kernel would take care of scheduling them.. As application we achieving parallelism by this approach. 


Exec : system call could be used to  execute your binary inherit from process that has invoked, meaning exec system call replace current process context with new one. 

For this scenario,  "packet handling & ftp file upload post receive message" -- exec system call in new process context is best approach to achieve. 


Exec system call could be used in different scenarios w.r.t requirements.