Posts

Why isn't the child PID always parent+1 in fork()?

Issue: I noticed that the difference between the child and parent process' PIDs was different while running in Vim vs regular terminal. My code: #include<stdio.h> #include<unistd.h> int main() { pid_t child_pid; //pid_t is a data type used to represent a process id child_pid = fork(); printf("\n\nProcess: my PID is %d, and my parent is %d", getpid(), getppid()); if(child_pid 0) { printf("\nChild's pid = %d",getpid()); } else if(child_pid > 0) { printf("\nParent Pid %d",getpid()); } else { printf("fork failed"); return 1; } return 0; } Inside vim : Notice that difference between the parent and child ID is 6 -- not 1, as I had expected. # (1st time execution) Process: my PID is 10362, and my parent is 10164 Parent Pid 10368 Process: my PID is 10368, and my parent is 10362 Child's pid = 10368 Press ENTER or typ...

Fork Bomb Part 2: Controlled Chaos - Monitoring Resource Exhaustion in QEMU

Image
I ran a forkbomb in Debian VM, run on Hypervisor: QEMU Specs of VM- Cores: 2 RAM Memory: 20GB I had set up 3 monitoring environments beside it in my host OS- 1) htop (monitor CPU + Processes) 2) dmesg -w (monitor kernel messages) 3) vmstat 1 (monitor system level metrics - process stats, memory stats, swap, io, cpu breakdown) within 4 seconds, all 8 cores in my CPU were all running at full speed . Note: The cores that I assigned to the VM were virtual cores , but in reality, the all 8 cores of my machine were being used The Resource temporatily unavailable message has already started popping up. This means that the system has hit the process limit and cannot create new processes. The fork bomb's exponential growth: 1 second: ~32 processes 2 seconds: ~1,024 processes 3 seconds: ~32,768 processes (system-wide PID exhaustion) 4 seconds: Complete scheduler collapse I suspect that Ubuntu is reaching is cgroups limit. I will look into this more in the future...

How VSCode Secretly Handles Git Authentication (And I Reverse Engineered It)

Reason: Until now after setting up my git repo using git init , i would immediately open it in VS Code as a project and would run the git commands through the terminal in VS Code. So, in the previous post, [link] I noticed that setting up a private git repo on both termux and my laptop required SSH, and it required me to generate a public key and add that key to github. However, I had never needed to go through such a process while linking a local folder to Git. That made me wonder whether this was an issue with my git repo being private. So, I started looking into it. After exploring, I found out that, wheter private or public, to link a git repo to the local folder, you need either an SSH key or a PAT token to authenticate your laptop. PAT tokens are high security modern version of passwords. They are used when you want to link repo using http Git stopped allowing real passwords to be entered for command line actions in 2021. You must generate these in Github s...

How I removed Digital Wellbeing (and other bloatware) from my android using my Ubuntu PC without rooting my phone

Environment: Phone : Samsung M13 Android Version : 14 Laptop OS : Ubuntu 24.04 Why remove it: Digital Wellbeing along with other bloatware apps are extra apps preinstalled into the device by the vendor. These apps take up space, drain battery and slow down performance. Many such apps even collect data behind the scenes such as user behaviour, location, personal data, etc. without taking explicit consent. Apps such as digital wellbeing are built into the operating system itself, and can't be removed directly. Some bloat apps like ARZone, Samsung TV plus, etc can be disabled, but not uninstalled. The below guide will help you uninstall these apps. Steps Step 1: Enable USB Debugging on the phone Enable Developer Options in the phone Settings app > About Phone > Click on Build Number 5 times Inside Developer Options --> Debugging Section --> Enable USB Debugging Step 2: Install ADB ADB (Android Debugging Bridge) is a command line tool ...

How I accidentally ran a fork bomb and crashed my laptop

⚠️ Warning: Do not execute the code shown in this post. It will make your system unresponsive. I wanted to observe linux kernel behavior under heavy load . My goal was to stress the CPU and observe scheduler behavior and per-process scheduling. So I asked ChatGPT for a shell script, that will apply "some" on the CPU. Unfortunately, I had no idea what a fork bomb was. Here's the script that I ran... ⚠️ Warning: do not execute. bad idea. terrible idea forkbomb() { forkbomb | forkbomb & }; forkbomb Yes. That is a fork bomb. Observations: The first time i ran the script, i saw fork() being called a couple of times in the terminal. So, I pressed Ctrl + C a couple of times, and assumed it to have stopped.. It hadn't. I closed the terminal and switched back to firefox -- where I immediately got an error message: "A web page is slowing down your browser. What would you like to do? -- Stop It or Wait" I clicked "Wait...

Understanding Malloc() Internals: What I've Learnt So Far

Image
 Intro I've been learning C language, and used malloc() multiple times as an inbuilt function. I was curious about what work it actually did under the hood and how did it actually allocate memory. So I did some research, and watched a couple of videos on youtube.. this was one of the videos that was very useful. https://youtu.be/HPDBOhiKaD8?si=T4HeEA3ACE3macqO This post documents everything that I have learnt so far. This is a work-in-progress, i will continue updating this post as i get more knowledge about this topic.   What is Malloc() malloc()   is a C function that is used to allocate memory for a program. You can access the system heap using the inbuilt C function:   malloc(). It tries to give your program a chunk of memory that is large enough to hold   size   bits. Concepts Memory   is the address space that is in the RAM or swap. Accessing Heaps in C Heaps can be accessed in C using sbrk()   -> main heap nmap()   -> additional ...