Tuesday, July 8, 2025

CSUMB Week 25 (2 July 2025 - 8 July 2025)

This week I learned that a single core on a CPU can only technically handle and run 1 process at a time; however, with context switching, it gives the illusion that a single core can run multiple processes at once. The fact that a CPU core can do this thousands of times per second to give us an illusion of a seamless operation blows my mind. 

Context switching involves CPU scheduling algorithms such as Round Robin, FIFO, SJF, etc. which determines which process should run next when a context switch does occur. I've also learned how to calculate these algorithms in a small-scale scenario when given a # of processes, an entry time, and duration to help me grasp a better understanding of how response time and turnaround time (TAT) are obtained and how they differ based on the scheduling algorithms are utilized. 

This week, I've also continued to learn more about C syntaxes and ran small demos on my MacBook to test and practice some of the concepts mentioned in the lecture videos. One of them was using the fork() function to create a process tree. In my practice code, I wrote:

pid_t childPid = fork();

char character = 'A';

if (childPid < 0) {

    printf("forking process failed\n");

}

if (childPid > 0){

    printf("This is the parent process.\n");

    printf("process_ID (PID): %d\n", childPid);

    printf("%c\n", num); 

    printf("end of process.\n\n");

}

if (childPid == 0){

    printf("This is the child process.\m");

    printf("pricess_ID (PID): %d\n", childPid);

    printf("%c\n", character);

    printf("end of process\n\n");

}

return 0;


I wrote this code to show how the PID number differs between a parent and a child process and how to separate them if I wanted to run a command/task for just one of those process (rather than running the same command simultaneously by all present processes). I then ran my code using a clang compiler on a zsh shell.

No comments:

Post a Comment