TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Process Management in Linux – Operating System

    Process Management ek important feature hai jo Linux Operating System me processes ko create, schedule aur manage karne ka kaam karta hai. Har process ko PID (Process ID) milta hai jo usko uniquely identify karta hai.


    Process in Linux

    Linux me process ek running program hota hai jo system resources use karta hai. Process ki dono types hoti hain:

    1. 1. Foreground Process: Jo directly user ke interaction me hoti hai. (e.g., nano filename.txt)

    2. 2. Background Process: Jo bina user ke direct interaction ke chalta hai. (e.g., ./script.sh &)


    Process States in Linux

    Linux me ek process multiple states me ho sakta hai:

    State Meaning
    Running (R) Process CPU use kar raha hai ya ready hai
    Sleeping (S) Process wait kar raha hai kisi event ya resource ka
    Stopped (T) Process suspend ya debug mode me hai
    Zombie (Z) Process terminate ho chuka hai par uska entry process table me hai

    💡 Diagram:

         ---> Running <---
         |               |
    New ---> Ready ---> Terminated
         |      |
         ---> Waiting


    Process Control in Linux

    Linux me processes ko control karne ke liye alag-alag commands aur system calls ka use kiya jata hai.

    1. Process Creation (fork(), exec())

    • fork(): Ek new child process create karta hai.

    • exec(): Ek naye program ko load aur execute karta hai.

    • Example:

    In C language

    #include <stdio.h>
    #include <unistd.h>


    int main() {
    fork(); // New process create hoga
    printf("Hello from process %d\n", getpid());
    return 0;
    }

    ✔ fork() ka use karke ek naye process ki copy banayi jati hai!


    2. Process Identification (ps, top)

    Har process ko PID (Process ID) milta hai jo usko uniquely identify karta hai.

    • ps command: Running processes dikhane ke liye.

    • top command: Real-time me process usage check karne ke liye.

    ✔ Example:

    ps aux | grep firefox (Firefox process ID dhundhne ke liye)

    top (Live process monitoring ke liye)


    3. Process Termination (kill, exit())

    Agar kisi process ko terminate karna ho, toh kill aur exit() ka use hota hai.

    ✔ Example:

    kill -9 1234 (Process ID 1234 ko forcefully terminate karega)


    4. Process Scheduling in Linux

    Linux me process scheduling ke liye scheduler algorithms ka use hota hai:

    • First Come First Serve (FCFS)

    • Round Robin (RR)

    • Completely Fair Scheduler (CFS) (Linux ka default scheduler)

    ✔ Process priority change karne ke liye:

    nice -n 10 ./a.out  (Low priority (Nice Value: 10))
    renice -5 -p 1234   (Change priority of process 1234)


    Conclusion

    ✅ Linux me processes ko manage karna ek important feature hai jo CPU scheduling, resource allocation aur memory management ka dhyan rakhta hai.
    ✅ fork() aur exec() ka use process creation ke liye hota hai.
    ✅ kill, ps, top, nice jaise commands process management me madad karte hain.

    Scroll to Top