> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aic-eec.com/computer-operation-systems/linux-os-dev.-engineer/process-management/process-state.md).

# Process State

เมื่อมีผู้ใช้งานสั่งให้โปรเซสเริ่มทำงาน ระบบปฏิบัติการจะทำการสร้างโปรเซสแล้วส่งเข้าไปสู่ Ready Queue เพื่อรอเข้าประมวลผลภายใน CPU และเมื่อหมดเวลาในการประมวลผล (สำหรับ Preemptive Scheduling) หรือเมื่อโปรเซสต้องรอการทำงานของ I/O ระบบจะเลือกโปรเซสจากสถานะ Ready Queue ตัวถัดไปเข้ามาประมวลผลใน CPU ทั้งนี้การเลือกจะดูที่เลข Priority และลำดับความสำคัญอื่นๆประกอบกัน จะวนเวียนเช่นนี้ไปเรื่อยๆจนกระทั่งโปรเซสทำงานเสร็จและออกจากระบบไป

<figure><img src="/files/aJAqeA72DFECoWBeSABq" alt=""><figcaption><p><em>สถานะการทำงานของโปรเซส</em></p></figcaption></figure>

ซึ่งเมื่อโปรเซสหนึ่งต้องหยุดการทำงานและออกมาจากการครอบครอง CPU ก็จะต้องทำการเก็บสถานะล่าสุดทั้งหมดเข้าไปใน PCB ของตัวเอง เพื่อรอคิวครั้งใหม่ ที่จะถูกเรียกจากตัวจัดลำดับของระบบปฏิบัติการ (scheduler) ต่อไป ซึ่งการสลับโปรเซสจะเรียกว่า Context Switch ดังรูปแสดงการสลับการทำงานระหว่างโปรเซสข้างล่าง

<figure><img src="/files/WaYRQ6jh7rCDgEg4Mzrn" alt=""><figcaption><p><em>การสลับการทำงานระหว่างโปรเซส</em></p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.aic-eec.com/computer-operation-systems/linux-os-dev.-engineer/process-management/process-state.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
