<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Boussebha Wassim</title>
    <description>The latest articles on DEV Community by Boussebha Wassim (@wassim31).</description>
    <link>https://dev.to/wassim31</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1035181%2F55a65837-f17d-4cfa-ba22-c873c16148d9.jpeg</url>
      <title>DEV Community: Boussebha Wassim</title>
      <link>https://dev.to/wassim31</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wassim31"/>
    <language>en</language>
    <item>
      <title>Saving the state of an interactive container</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Fri, 27 Sep 2024 16:16:35 +0000</pubDate>
      <link>https://dev.to/wassim31/saving-the-state-of-an-interactive-container-3pnj</link>
      <guid>https://dev.to/wassim31/saving-the-state-of-an-interactive-container-3pnj</guid>
      <description>&lt;p&gt;Sometimes we need to start a docker container in an interactive shell for testing purposes , and during the process you might wrote some application code , downloaded some big chunks of files, or configured the environment according to your use-cases , but starting the container interactively will make it destroyed once an interrupt is done ( 0 or -1 ) .&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -it --rm --mount type=bind,source="$(pwd)"/work,target=/work -p 8888:8888 opencvcourses/opencv:440&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-it&lt;/code&gt; starts an interactive shell. This switch is always needed to start the container. Otherwise, it will start and stop instantly.&lt;br&gt;
&lt;code&gt;--rm&lt;/code&gt; specifies to kill the container after it is exited.&lt;br&gt;
&lt;code&gt;--mount&lt;/code&gt; creates persistent storage to save all the work. Read more about it here⁠.&lt;br&gt;
&lt;code&gt;-p&lt;/code&gt; is used to expose a container's port to the host.&lt;br&gt;
&lt;strong&gt;Note: Run this command in the parent directory of work folder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;you can save the state by commiting the changes to the pulled image.&lt;br&gt;
&lt;code&gt;$ docker ps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker commit &amp;lt;container_id&amp;gt;  repo/testimage:version3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;While this will work, this approach is considered poor practice by the Docker community. Best way to go is using a Dockerfile.&lt;/p&gt;

&lt;p&gt;Yeah, I think that's the right way for production for sure. But many of us are just using docker locally as a slimmed down version of virtualbox, and just want the damn state saved, exactly as it is. And don't want extra volumes on our local drives either&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Install OpenCV 4.5 on Ubuntu 22.04</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Fri, 27 Sep 2024 05:50:45 +0000</pubDate>
      <link>https://dev.to/wassim31/install-opencv-45-on-ubuntu-2204-306i</link>
      <guid>https://dev.to/wassim31/install-opencv-45-on-ubuntu-2204-306i</guid>
      <description>&lt;p&gt;OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly for real-time computer vision.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But it's installation can be very tricky in an environment like Linux, so let's follow a correct installation process&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Build OpenCV for Python and C++ from sources
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Let's open the most recent release of opencv to the date of this video capturing:&lt;br&gt;
&lt;a href="https://github.com/opencv/opencv/releases/tag/4.5.1" rel="noopener noreferrer"&gt;https://github.com/opencv/opencv/releases/tag/4.5.1&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a tmp folder for all archives:&lt;br&gt;
&lt;code&gt;mkdir ~/opencv4.5-tmp &amp;amp;&amp;amp; cd ~/opencv4.5-tmp&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We need to download opencv sources:&lt;br&gt;
&lt;code&gt;wget https://github.com/opencv/opencv/archive/4.5.1.zip -O opencv.zip&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We need to download opencv-contrib sources:&lt;br&gt;
&lt;code&gt;wget https://github.com/opencv/opencv_contrib/archive/4.5.1.zip -O opencv_contrib.zip&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unzip the opencv files:&lt;br&gt;
&lt;code&gt;unzip opencv.zip&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unzip the opencv-contrib files:&lt;br&gt;
&lt;code&gt;unzip opencv_contrib.zip&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Move the files to simple directories:&lt;br&gt;
&lt;code&gt;mv opencv-4.5.1/ opencv&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Move opencv-contrib files to simple directories:&lt;br&gt;
&lt;code&gt;mv opencv_contrib-4.5.1/ opencv_contrib&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make build directory:&lt;br&gt;
&lt;code&gt;cd opencv &amp;amp;&amp;amp; mkdir build &amp;amp;&amp;amp; cd build&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy and run the following command. Install cmake if it is not available on the system.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   cmake &lt;span class="nt"&gt;-D&lt;/span&gt; &lt;span class="nv"&gt;CMAKE_BUILD_TYPE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;DEBUG &lt;span class="se"&gt;\&lt;/span&gt;
         &lt;span class="nt"&gt;-D&lt;/span&gt; &lt;span class="nv"&gt;CMAKE_INSTALL_PREFIX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/opencv4.5-custom &lt;span class="se"&gt;\&lt;/span&gt;
         &lt;span class="nt"&gt;-D&lt;/span&gt; &lt;span class="nv"&gt;OPENCV_EXTRA_MODULES_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/opencv4.5-tmp/opencv_contrib/modules &lt;span class="se"&gt;\&lt;/span&gt;
         &lt;span class="nt"&gt;-D&lt;/span&gt; &lt;span class="nv"&gt;OPENCV_GENERATE_PKGCONFIG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON &lt;span class="nt"&gt;-DOPENCV_GENERATE_PKGCONFIG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON &lt;span class="se"&gt;\&lt;/span&gt;
         &lt;span class="nt"&gt;-D&lt;/span&gt; &lt;span class="nv"&gt;BUILD_EXAMPLES&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON ..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Make the project:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   make -j4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Install opencv:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Ensure that it is updated in the library storage:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo ldconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;## Configure C++ project to work with opencv&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your editor of choice (vim in my case)&lt;/li&gt;
&lt;li&gt;Create a folder "~/projects/HelloOpenCV"&lt;/li&gt;
&lt;li&gt;Paste the &lt;code&gt;main.cpp&lt;/code&gt; code to the &lt;code&gt;main.cpp&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Firstly, let's try to compile our application with g++ as usual:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   g++ -Wall -o main main.cpp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We see that it cannot find our library headers&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For that we need to provide path to the headers and linker flags. The best way to find them
all in one place is to use the utility module pkg-config. Remember we provided an additional
argument to our cmake generation? So, let's execute the following:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/parallels/opencv4.5-custom/lib/pkgconfig
   pkg-config --cflags --libs opencv4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Add all flags to compilation command:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   g++ -Wall -o main main.cpp $(pkg-config --cflags --libs opencv4)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or a more explicit version for our particular sample:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   g++ -Wall -o main main.cpp \
      -I/home/parallels/opencv4.5-custom/include/opencv4 \
      -L/home/parallels/opencv4.5-custom/lib \
      -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_core
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Real-time Disk Size Expanding in a Linux virtual machine</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Fri, 05 Jul 2024 15:14:35 +0000</pubDate>
      <link>https://dev.to/wassim31/real-time-disk-size-expanding-in-a-virtual-machine-on-linux-machine-307i</link>
      <guid>https://dev.to/wassim31/real-time-disk-size-expanding-in-a-virtual-machine-on-linux-machine-307i</guid>
      <description>&lt;p&gt;I was compiling the Linux kernel from source and i had a vm running AlmaLinux with 20GB Logical volume, so i attained the maximum size, i had to expend my disk size without losing my data, the progress of a 12 hours compilation process(yes heavy kernel, and a weak hardware)&lt;/p&gt;

&lt;p&gt;this solution is used in storage management in cloud services providers AWS, Azure ..&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Linux Distribution&lt;/em&gt;&lt;/strong&gt; : AlmaLinux 9.4 on Vmware Workstation 7&lt;/p&gt;

&lt;p&gt;When you expand the disk size of your Linux virtual machine (VM) on VMware, you must adjust the partitions within the system to utilize the additional space. &lt;/p&gt;

&lt;p&gt;This guide will walk you through the steps required to resize the partitions and filesystems using bash.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Before you begin, ensure you have:&lt;/p&gt;

&lt;p&gt;Expanded the disk size of your VM in VMware.&lt;/p&gt;

&lt;p&gt;Root or sudo access to your Linux VM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Identify the New Disk Size&lt;br&gt;
First, verify the current disk and partition sizes using the lsblk command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lsblk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will show all block devices and their partitions. Identify the disk you have expanded. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0                 11:0    1  988M  0 rom  
nvme0n1            259:0    0  100G  0 disk 
├─nvme0n1p1        259:1    0    1G  0 part /boot
└─nvme0n1p2        259:2    0   19G  0 part 
  ├─almalinux-root 253:0    0   17G  0 lvm  /
  └─almalinux-swap 253:1    0    2G  0 lvm  [SWAP]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Resize the Partition&lt;br&gt;
Use the &lt;strong&gt;growpart&lt;/strong&gt; utility to resize the partition. If it's not already installed, you can install it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo dnf install cloud-utils-growpart

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, resize the partition nvme0n1p2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo growpart /dev/nvme0n1 2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Resize the Physical Volume (PV)&lt;br&gt;
Next, resize the physical volume to recognize the expanded partition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo pvresize /dev/nvme0n1p2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Verify the Physical Volume Size&lt;br&gt;
Verify the changes using the pvs command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo pvs

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Resize the Logical Volume (LV)&lt;/p&gt;

&lt;p&gt;Assuming you want to allocate all the new space to the root logical volume (almalinux-root):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo lvextend -l +100%FREE /dev/almalinux/root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Determine the Filesystem Type&lt;br&gt;
Before resizing the filesystem, determine the filesystem type. You can do this with the &lt;strong&gt;df -Th&lt;/strong&gt; or &lt;strong&gt;lsblk -f&lt;/strong&gt; commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df -Th

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lsblk -f

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Resize the Filesystem&lt;br&gt;
Depending on the filesystem type, use the appropriate command to resize the filesystem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For ext4:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo resize2fs /dev/almalinux/root

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For xfs:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo xfs_growfs /

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Verify the Changes&lt;br&gt;
Finally, verify that the new space is available using the lsblk and df -h commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lsblk
df -h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By following these steps, you can effectively utilize the additional disk space after expanding your Linux VM disk on VMware. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>CAFE BABE, if you know , you know JVM enthusiast.</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Sat, 30 Dec 2023 22:04:20 +0000</pubDate>
      <link>https://dev.to/wassim31/cafe-babe-if-you-know-you-know-jvm-enthusiast-nda</link>
      <guid>https://dev.to/wassim31/cafe-babe-if-you-know-you-know-jvm-enthusiast-nda</guid>
      <description>&lt;p&gt;CAFE BABE, if you know , you know JVM enthusiast.&lt;/p&gt;

&lt;p&gt;Each program has a magic word in it's machine code representation that defines it's identity among multiple other files .&lt;/p&gt;

&lt;p&gt;if you open a compiled java file aka file.class with a hex editor like xxd tool in Linux , you'll find the first hex words : CAFE BABE .&lt;/p&gt;

&lt;p&gt;But why it is so magical that it has to add in each class file is probably the most important question to be asked.&lt;br&gt;
Well, James Gosling explained why: –&lt;/p&gt;

&lt;p&gt;We used to go to lunch at a place called St Michael’s Alley. According to local legend, in the deep dark past, the Grateful Dead used to perform there before they made it big. It was a pretty funky place that was definitely a Grateful Dead Kinda Place. When Jerry died, they even put up a little Buddhist-esque shrine. When we used to go there, we referred to the place as Cafe Dead. Somewhere along the line, it was noticed that this was a HEX number. I was re-vamping some file format code and needed a couple of magic numbers: one for the persistent object file, and one for classes. I used CAFEDEAD for the object file format, and in grepping for 4 character hex words that fit after “CAFE” (it seemed to be a good theme) I hit on BABE and decided to use it. At that time, it didn’t seem terribly important or destined to go anywhere but the trash can of history. So CAFEBABE became the class file format, and CAFEDEAD was the persistent object format. But the persistent object facility went away, and along with it went the use of CAFEDEAD – it was eventually replaced by RMI.&lt;/p&gt;

</description>
      <category>java</category>
      <category>linux</category>
      <category>programming</category>
      <category>reverse</category>
    </item>
    <item>
      <title>How your program's functions are handled in memory ?</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Fri, 29 Dec 2023 15:40:54 +0000</pubDate>
      <link>https://dev.to/wassim31/how-your-programs-functions-are-handled-in-memory--afl</link>
      <guid>https://dev.to/wassim31/how-your-programs-functions-are-handled-in-memory--afl</guid>
      <description>&lt;p&gt;Because i always forget how the kernel is handling the program's functions in the call stack , i'll write about it so i come back after months or someone else will :) .&lt;/p&gt;

&lt;p&gt;So hello , let's do it in C in a x86-64bits machine, why ? because it's my favorite language .&lt;/p&gt;

&lt;p&gt;first , when you compile your C code ( gcc -c main main.c ), you get an object file main.o that will be linked later ( manually or dynamically ) with other already compiled standard code ( like your famous printf() ) , you get an executable file , ELF64 in my case.&lt;br&gt;
okay , when you disassemble either with objdump or gdb , you can see the assembly code of your program :&lt;br&gt;
gdb ./main&lt;br&gt;
disassemble function&lt;/p&gt;

&lt;p&gt;you'll find some sections like .text , .bss or .data , heap and the stack these are the sections of the virtual address space of your program .&lt;/p&gt;

&lt;p&gt;what concern us is the .text section , it contains the code ( instructions to be executed [ for example int x = 3 will have the equivalent of movl  $0x3,-0x4(%rbp)]) &lt;/p&gt;

&lt;p&gt;okay , good , what concerns us is how the functions main() and function() are handled in the stack (the section where the functions resides) .&lt;/p&gt;

&lt;p&gt;before , the CPU unit has some special registers called %rbp , %rsp ( the base pointer and the stack pointer ) to manipulate the scope of the functions.&lt;/p&gt;

&lt;p&gt;%rbp : is used to access the memory words by adding values to it like the example we had : movl  $0x3,-0x4(%rbp)&lt;br&gt;
%rsp : will always points to the top of the stack.&lt;/p&gt;

&lt;p&gt;so the first thing we need to do is to push the value of the old %rbp ( because it's used by other functions to do the same thing , in this case the main() function which called the function() ) .&lt;/p&gt;

&lt;p&gt;then , we push the return address to the stack so the main() function resumes it's execution where it stopped ( in this case it will return to line 13). , this information is retrieved from register r14 in ARM processors for example.&lt;/p&gt;

&lt;p&gt;then we'll put the new value of the base pointer %rbp ( the one we said used for accessing memory words in the scope ) to the value of %rsp , so the top of the stack .&lt;/p&gt;

&lt;p&gt;this process of handling the %rbp and %rsp is called function prologue and it's done in each function start ( as you see in the assembly code ) .&lt;/p&gt;

&lt;p&gt;this is how it's done with the initialization of the function scope in multiple architectures and systems similarly.&lt;/p&gt;

&lt;p&gt;now we'll use the function call stack by putting the local variables , the function parameters etc , these specific details follows calling conventions:&lt;br&gt;
&lt;a href="https://lnkd.in/eUNNAiXH" rel="noopener noreferrer"&gt;https://lnkd.in/eUNNAiXH&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;one of the conventions to follow in x64 architectures for example is SYSTEM V&lt;br&gt;
the registers used for function parameters handling &lt;br&gt;
The first is placed in rdi, the second in rsi, the third in rdx, and then rcx, r8 and r9. Only the 7th argument and onwards are passed on the stack , the left most parameter is passed first on the stack , and then the old value of the base pointer , then it's followed by the local variables of the function.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>c</category>
      <category>x86</category>
      <category>memory</category>
    </item>
    <item>
      <title>what the heck is locality of reference , why i will waste brain cells bytes to know it?</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Mon, 25 Sep 2023 23:51:05 +0000</pubDate>
      <link>https://dev.to/wassim31/what-the-heck-is-locality-of-reference-why-i-will-waste-brain-cells-bytes-to-know-it-1l48</link>
      <guid>https://dev.to/wassim31/what-the-heck-is-locality-of-reference-why-i-will-waste-brain-cells-bytes-to-know-it-1l48</guid>
      <description>&lt;p&gt;Locality of Reference is a critical Computer Science topic and helps improving the software's performance if the programmer is aware of it .&lt;/p&gt;

&lt;p&gt;Programs that tend to exhibit good locality are those who're constituted of components that tend to reference data items that are near other recently referenced data items or that were recently referenced themselves .&lt;/p&gt;

&lt;p&gt;There is 2 types of locality : &lt;/p&gt;

&lt;p&gt;1- Temporal locality : if a main memory's word is referenced once , and there are potential references in the near future , it should be in the cache memory.&lt;/p&gt;

&lt;p&gt;2- Spatial locality : if a memory location is referenced once, then the program is likely to reference a nearby memory location in the near future ; A good example is a programming block which is logically distinguishable that is : Traversing a contiguous array of data using a loop statement .&lt;/p&gt;

&lt;p&gt;Okay thank you for giving me information that i can get from Wikipedia , how the heck that will help me improve my programming skills &amp;amp; performance ?&lt;/p&gt;

&lt;p&gt;Answer : We have the following example that performs matrix values sum&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffj4k7st70rjte1a3ja4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffj4k7st70rjte1a3ja4.png" alt="example" width="800" height="637"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the sumarraycols() function in Figure 6.19(a) computes the same result as the sumarrayrows function in Figure 6.18(a). The only difference is that we have interchanged the i and j loops. &lt;/p&gt;

&lt;p&gt;But What impact does interchanging the loops have on its locality?&lt;/p&gt;

&lt;p&gt;The sumarraycols() function suffers from poor spatial locality because it scans&lt;/p&gt;

&lt;p&gt;the array column-wise instead of row-wise. Since C arrays are laid out in memory row-wise.&lt;/p&gt;

&lt;p&gt;The examples retrieved from the book : Computer Systems - Programmer's perspective.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>cpu</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>How the heck a C program is compiled from human comprehensible language to 0's and 1's</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Tue, 28 Feb 2023 01:38:09 +0000</pubDate>
      <link>https://dev.to/wassim31/how-the-heck-a-c-program-is-compiled-from-human-comprehensible-language-to-0s-and-1s-2kkg</link>
      <guid>https://dev.to/wassim31/how-the-heck-a-c-program-is-compiled-from-human-comprehensible-language-to-0s-and-1s-2kkg</guid>
      <description>&lt;p&gt;You may wondered how the programming languages lexemes are turned into a series of 0's and 1's aka binary files ?&lt;/p&gt;

&lt;p&gt;Figure 2.11 - Book reference : Operating system concepts.&lt;/p&gt;

&lt;p&gt;Let's discover that together step by step :&lt;/p&gt;

&lt;p&gt;Usually programs a.out or program.exe ( games , word processors , web browsers ..) resides in your disk as a binary executable file , and in order to execute one of them , you need to fetch it from disk and put in memory , and it waits until it's scheduled to run and becomes a running program also known as a "process" which have a specific amount of memory addresses and executed by the units of cpu's core with the help of specific registers like program counters , IR ... and general-purpose registers .&lt;/p&gt;

&lt;p&gt;but we don't write operating systems and Enterprise systems with binary right?&lt;/p&gt;

&lt;p&gt;We need a human readable language , let's chose a compiled programming language like C to know the process of compilation .&lt;/p&gt;

&lt;p&gt;After writing your program.c source code with human readable C , the source code is compiled &amp;amp; assembled to a relocatable object file program.o ( machine code that can be disassembled and turned into a geek-readable assembly ) ( we will talk about phases of compilation ( lexing , parsing , AST...) in future articles ) .&lt;/p&gt;

&lt;p&gt;So we have now a object file , but we may called several functions like printf() which is also written by system programmers before to give us a layer of abstraction and increase our productivity , and compiled aka turned into an object file , it's part of GCC .&lt;/p&gt;

&lt;p&gt;we need now to link all those object files and make them a single binary executable file that can be loaded into memory , this mechanism is done by what we call a " Linker " . (this is static linking)&lt;/p&gt;

&lt;p&gt;the mechanism of loading the binary executable file into memory so it can be executed by one of the cpu's core is done by the loader , it's also responsible of addresses reallocation in memory..&lt;/p&gt;

&lt;p&gt;You may heard about DLL ( dynamically linked libraries ) files in Windows right ? now we speak about dynamic linking . actually , most systems allows programs to dynamically link the libraries even if the program is already loaded and started execution ( that's good from memory optimization prospective, because the programmer may include a library and doesn't use it during runtime , i am sure we all did that before )&lt;/p&gt;

&lt;p&gt;you know that modern systems allows multiple processes to share DLL ? yes they do!&lt;/p&gt;

&lt;p&gt;And now you have a binary executable program into memory , also known as a process , with it's own memory addresses .&lt;/p&gt;

&lt;p&gt;I will talk deeper next time about the compilation phases , and how the cpu fetch &amp;amp; decode &amp;amp; execute instructions &amp;amp; data from the bounded virtual memory of the process.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why the heck the _state variable in task_struct structure is 4 bytes</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Tue, 28 Feb 2023 01:34:32 +0000</pubDate>
      <link>https://dev.to/wassim31/why-the-heck-the-state-variable-in-taskstruct-structure-is-4-bytes-3nkh</link>
      <guid>https://dev.to/wassim31/why-the-heck-the-state-variable-in-taskstruct-structure-is-4-bytes-3nkh</guid>
      <description>&lt;p&gt;According to Robert Love the Author of the book Linux Kernel developement &amp;amp; Linux kernel source :&lt;/p&gt;

&lt;p&gt;In the Linux kernel , specifically in the PCB ( process control block ) which a structure that represents the process in the kernel .&lt;/p&gt;

&lt;p&gt;The process state is represented by a combination of six state flags, which are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TASK_RUNNING&lt;/strong&gt;: The process is currently running or ready to run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TASK_INTERRUPTIBLE:&lt;/strong&gt; The process is waiting for a specific event to occur and can be interrupted by a signal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TASK_UNINTERRUPTIBLE&lt;/strong&gt;: The process is waiting for a specific event to occur and cannot be interrupted by a signal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;__TASK_STOPPED&lt;/strong&gt;: The process has been stopped (e.g. by a SIGSTOP signal) and can be resumed later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;__TASK_TRACED&lt;/strong&gt;: The process is being traced by another process (e.g. a debugger).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TASK_DEAD&lt;/strong&gt;: The process has terminated and is waiting to be reaped by its parent process.&lt;/p&gt;

&lt;p&gt;Each of these flags can be set or cleared to represent the different states that a process can be in. For example, a process that is both &lt;strong&gt;TASK_INTERRUPTIBLE&lt;/strong&gt; and &lt;strong&gt;TASK_UNINTERRUPTIBLE&lt;/strong&gt; might be waiting for a disk I/O operation to complete, and can be interrupted by a signal but cannot be killed until the I/O operation is finished.&lt;/p&gt;

&lt;p&gt;In other words, a process can have multiple states at once, depending on which combination of flags is set.&lt;/p&gt;

&lt;p&gt;This state is saved in an *&lt;em&gt;UNSIGNED INTEGER *&lt;/em&gt;, that means 32 bits , that means 2³² possible values , but we need only 2⁶ , so 64 possible states as a maximum .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzyjgn454zk879nczq4w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzyjgn454zk879nczq4w.png" alt="Image description" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the reason is the following : &lt;/p&gt;

&lt;p&gt;There are some predefined functions that manages the process's state such as &lt;strong&gt;READ_ONCE/WRITE_ONCE&lt;/strong&gt; that obliges this variable to be an unsigned INT , it's used to be a volatile Long ; here are the commits : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/torvalds/linux/commit/2f064a59a11ff9bc22e52e9678bc601404c7cb34#diff-f8d8a1568ae83bbff6f40f9c70559a4f7dbf426a397131ba9d4fbfb947ea5222R669" rel="noopener noreferrer"&gt;https://github.com/torvalds/linux/commit/2f064a59a11ff9bc22e52e9678bc601404c7cb34#diff-f8d8a1568ae83bbff6f40f9c70559a4f7dbf426a397131ba9d4fbfb947ea5222R669&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading &amp;lt;3 .&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why the heck gateways are invented in computer networks ?</title>
      <dc:creator>Boussebha Wassim</dc:creator>
      <pubDate>Tue, 28 Feb 2023 01:24:34 +0000</pubDate>
      <link>https://dev.to/wassim31/why-the-heck-gateways-are-invented-in-computer-networks--50lf</link>
      <guid>https://dev.to/wassim31/why-the-heck-gateways-are-invented-in-computer-networks--50lf</guid>
      <description>&lt;p&gt;&lt;strong&gt;I've always wondered why the default gateway is needed in computer networks , I realized finally, so i wanted to share that with you guys :) .&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;let's take an example , an HTTPS request to Google.com , a DATA chunk is generated , which contains data like the destination google's IP address resolved from DNS , type of HTTP request ( GET OR POST ..) etc...&lt;br&gt;
The encapsulation process will start in the TCP/IP Suite installed in your device , and it's like the following :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frlc3ctt4on44ifu4obee.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frlc3ctt4on44ifu4obee.png" alt="Image description" width="800" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;each layer will perform some work on this DATA sent to Google's Server , the first inferior level is the Transport layer , SSL/HTTP mainly runs on top of TCP , so the connection oriented protocol will prepare the TCP tunnel by performing the TCP handshake with the server and allow TCP tunneling to exchange both data and metadata .&lt;/p&gt;

&lt;p&gt;The TCP will also segment the DATA and does the sequencing to avoid incoherent DATA in the destination , also adds both source and destination operating system processes ports( TCP Does a lot of things , google to know more ).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foo43904rf85rwnwllekv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foo43904rf85rwnwllekv.png" alt="Image description" width="650" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we will have now a bunch of segmented , sequenced pdu's called Segments , with DATA and the TCP Header , it passes to the next layer .&lt;/p&gt;

&lt;p&gt;The Internet Layer , for example IPv4 , the layer will add the IPv4 header that contains importantly the source and destination IP address, so we will have now a packet , an important header will be added , it's the TTL , time to live , how much time the packet will live in the Internet routers around the world , each time it passed a Router , the value of the TTL will get decremented until it reaches the zero and the packet get destroyed .&lt;/p&gt;

&lt;p&gt;Now the most important thing , we have an IPv4 packet ready to be routed in the Internet , but it needs to pass through Data Link layer , the Ethernet ( even 802.3 or 802.11 ) , this layer will add to the packet both source and destination MAC address to make sure that the data is sent to the correct device , since the MAC address is the unique network identifier for each device, and ip addresses can change .&lt;/p&gt;

&lt;p&gt;It's possible for the device that sent this HTTPS request to know the destination mac address if we're on the same local area network , that's thanks to the Address resolution protocol by sending a broadcast ipv4 packet to all devices in the same network and saving results on the ARP table which contains the mac address for each device connected to this specific router interface.&lt;/p&gt;

&lt;p&gt;the ethernet frame need to be transformed into bits and sent via UTP or fiber optic cables to our router so it routes it to the google's server .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7ut3adawhq6eul7ex3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7ut3adawhq6eul7ex3p.png" alt="Image description" width="559" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this situation , the device needs to know the mac address of the router , so the ethernet frame will be sent to the router , and routers communicates with each other with layer 3 addresses aka ip addresses .&lt;br&gt;
so the device will just need to replace the destination address with the gateway aka the local ip address of the router , and get it's mac address via the ARP table , and put it in the ethernet frame .&lt;br&gt;
and the packet is sent.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
