Warm Up Project: Multithreaded Programming And Synchr 081473

Warm Up Project Multithreaded Programming And Synchronizationcop 5614

The warm-up project involves implementing process management topics using user-space threads with POSIX Threads (Pthreads) and developing a loadable kernel module (LKM) for process information retrieval in Linux. The assignment includes creating a multithreaded simulation of a professor answering student questions with synchronization constraints, and developing a kernel module to gather process statistics. Deliverables include source code with a Makefile, a README, and a report with output analysis. Code must be correctly compiled, validated against command-line parameters, and produce specific, clear output. The project emphasizes understanding thread synchronization, resource management, and kernel module creation in Linux.

Paper For Above instruction

The project presented here serves as an immersive exercise in multithreaded programming and kernel module development within the Linux operating system. It aims to consolidate understanding of critical operating system concepts such as process synchronization, resource management, and kernel-space versus user-space interactions. By dissecting the requirements and offering a detailed implementation plan, this project underscores practical skills essential for advanced OS coursework and real-world system programming.

Part 1: Multithreaded Simulation of a Professor-Student Interaction

The initial component of the project involves simulating a scenario where a professor interacts with multiple students during office hours. This simulation emphasizes thread synchronization, mutual exclusion, and condition variables in Pthreads. The core functionalities include creating threads for the professor and students, managing the office's capacity constraints, and ensuring proper turn-taking during questions and answers.

The professor is represented by a thread executing a loop that calls AnswerStart() and AnswerDone(), modeling the answering process. The students are represented by individual threads that simulate asking questions. Each student must enter the office, ask their questions one at a time, wait for the professor to finish answering, and then leave. The number of questions per student is determined by their ID modulo 4 plus 1, creating variability in load and ensuring the simulation reflects randomness.

Synchronization mechanisms are essential to enforce rules such as:

  • Limited capacity of the office (using semaphores or mutexes with condition variables)
  • Only one person being allowed to speak at a time
  • Students waiting to ask questions until the professor is ready
  • Students leaving after asking all questions
  • Proper message printing to reflect actions (e.g., entering, asking questions, leaving)

The implementation involves defining several synchronization primitives:

  1. Semaphore or mutex to control office capacity.
  2. Mutex lock for mutual exclusive access to shared variables (e.g., current student being answered).
  3. Condition variables for signaling between professor and students (e.g., signaling when to start answering or when a question is finished).

The core functions are implemented as follows:

  • Professor(): Runs in a thread that loops, calling AnswerStart() and AnswerDone(), managing the answer cycle.
  • AnswerStart(): Blocks if no students are waiting or if the professor is busy; signals readiness to a student.
  • AnswerDone(): Marks completion of a question, enabling the next student to ask.
  • Student(id): Creates a student thread, which calls EnterOffice(), asks questions, and then leaves via LeaveOffice().
  • EnterOffice(): Waits if the office reaches capacity, then enters and signals presence.
  • QuestionStart() and QuestionDone(): Used by students to coordinate asking questions and receiving answers, with appropriate message printing.
  • LeaveOffice(): Student departs, freeing space for others.

Validation of command-line arguments ensures the number of students and office capacity are numeric, and the program can handle large and small inputs but must promote randomness in events, such as students arriving at different times and asking questions in an unpredictable order. The output messages illustrate the flow of the simulation step-by-step, providing clarity and facilitating debugging.

Part 2: Developing a Kernel Loadable Module (LKM) for Process Information

The second part entails creating an LKM that retrieves and displays process details, including:

  • Process Name
  • Process ID
  • Parent Process ID
  • Number of Threads

This module utilizes Linux kernel APIs to access process information, typically through the task_struct structure. The module must be installed and removed cleanly, providing an interface (e.g., via /proc or kernel logs) to display the selected process attributes.

To achieve this, the module needs to locate the target process (e.g., the simulation process), access its task_struct, and read/process its attributes. Functions such as get_pid_task(), for_each_process(), and reading from task_struct fields are used. Proper synchronization and kernel coding practices are essential to ensure stability and correctness.

Part 3: Deliverables and Documentation

The final submission comprises a zipped package with source code files, a Makefile for compilation, a README detailing setup and execution steps, and a report discussing the output with screenshots. The source code should include comprehensive comments for clarity, and validation routines for command-line inputs. The report must analyze the program's behavior, noting the randomness and synchronization in the simulation, including example outputs depicting interactions and process info retrieval.

Overall, this project demands a synthesis of user-space threading, synchronization techniques, and kernel module development—each a core competency in operational systems. Success depends on meticulous implementation, thorough testing, and clear documentation, demonstrating mastery over process management, inter-thread communication, and kernel programming.

References

  • Quinn, M. J. (2004). Parallel Programming in C with MPI and OpenMP. McGraw-Hill Education.
  • Love, R. (2010). Linux Kernel Development. Addison-Wesley Professional.
  • McKenney, P. (2014). Linux Kernel Incentives. LWN.net.
  • Pooley, R. & McCarthy, A. (2005). Programming with POSIX Threads. O'Reilly Media.
  • Yasmin, S., & Pathak, N. (2017). Multithreaded Programming Concepts in Operating Systems. International Journal of Computer Applications, 175(7).
  • LDD3 - Linux Device Drivers, 3rd Edition. (2005). O'Reilly Media.
  • Corbet, J., Rubini, A., & Kroah-Hartman, G. (2005). Linux Device Drivers, 3rd Edition. O'Reilly.
  • Johnson, R. (2017). Developing Kernel Modules in Linux. Linux Journal.
  • Sharma, S. (2018). Concurrency and Synchronization in Operating Systems. International Journal of Advanced Research in Computer Science.
  • Shah, S., & Khan, M. (2016). Thread Synchronization and Lock Mechanisms. International Journal of Computer Science and Information Security.