Posts

Operating System - Learn Thread with C/C++, Python

Image
Learn Thread with C/C++, Python  What is Thread ?  Thread is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system. Multiple threads can reside in a process, executing concurrently and sharing resources such as memory. While processes do not share resources, thread share resources in a process, and this leads to smaller overhead between context switching compared to processes.  Program VS Process VS Thread Comparing process with thread  Process   Heavyweight unit of kernel scheduling due to their resources  Resources include memory, file handles, sockets, device handles, windows and PCB Creating or destroying a process is relatively expensive as resources must be acquired or released.  Thread  Kernel Thread 

Operating System - Learn Process with C/C++, Python

Image
 Learn Process with c/c++, python What is Process ? A process is a execution unit of application(an application is static entity which is stored in storage devices) that is loaded on memory and is being executed. This means that a process is something that is actually doing something on our computer and is a basic unit of execution in an operating system. Process address space is not directly mapped to the physical memory, but they utilize the concept of virtual memory. This is done by the help of MMU(hardware component that translates virtual memory to physical memory).  Benefits of using virtual memory  Large programs can be written, as available virtual address space size can be larger than actual physical memory size  Less I/O required and this leads to faster and easier way of swapping processes Anatomy of a Process 

UDP with Python

  UDP with socket programming in python UDP(User Datagram Protocol) Applications send messages(datagrams) to other hosts on an IP network.   Prior communications are not required to set up communication channels  Is a simple connection-less communication model(no handshakes) with a minimum of protocol mechanism.  There is no guarantee of delivery, ordering, or duplicate protection. Suitable for purposes where error checking and connections are not necessary.   TCP vs UDP  TCP  Reliable : TCP manages message acknowledgment, re-transmission and timeouts. If data gets lost along the way, data will be re-sent.  Ordered : even if data segments arrive in wrong order, TCP buffers the out of order data until all data can be properly reordered and delivered to the application  Heavy Weight :

Encryption with Python

Image
 Encryption  The most famous hash functions like MD5 algorithm and SHA256 algorithm can be utilized with small lines of codes in python. I find it really beautiful and these are one of reasons I love python so much.  Let's look at the md5 first. The principle behind the hash encryption is that, the process of authentication is done by comparing encrypted data. So we don't need to decrypt the encrypted data. So, let's check out some cool functions using md5 with python.    But there are some good reasons that you shouldn't use the md5 anymore. You can check why md5 is not very secure by putting your encrypted data into md5 decyptor .  There is some ways that you can improve the security of md5 by adding salt. Here is another fancy functions provided by python that you can easily add salt.    You can also use another hashing functions like sha1, sha256, whirlpool and so on. You can check the available algorit

Buffer related to socket.recv()

Image
Size of the buffer and socket.recv()  Let's look at the sample code below.  This is a simple server side code that will send "Welcome to the server" when a client connects to the server.  Now let's look at client side code. This will receive the message sent by the server with a buffer size of 8. That means whenever a message that is longer than 8 bytes long will be divided into pieces. We can see that the maximum size of the message is the buffer. So, programmer must ensure all the data has been received properly. This can be done simply utilizing a variable called HEADERSIZE. This code was from sentdex, who is really a great programmer and a great tutor.  Now let's look at the server side code with HEADERSIZE  We will simply send a message that includes length of the message and set a header which has a length of HEADERSIZE(

TCP with Python

Image
TCP with socket programming in python  TCP (Transmission Control Protocol)  Connection-oriented : Client and Server connection must be established before transferring data  Three way handshake, re-transmission, error-detection increases the reliability but lengthens latency TCP abstracts the application's communication from the underlying networking details  Used by : WWW, email, FTP, secure shell, peer to peer file sharing, streaming media  Optimized for reliability, and this may require long delivery time  Functions provided by TCP  Three way handshake  Requesting re-transmission of lost data  Rearrange out of order data Helps minimize network congestion to reduce the occurrence of other problems