ลำดับความสำคัญของโพรเซสด้วย nice, renice และสัญญาณ
ควบคุมปริมาณ CPU ที่โพรเซสได้รับด้วย nice และ renice และเรียนรู้ว่าสัญญาณช่วยสื่อสารกับโพรเซสที่กำลังทำงานได้อย่างไร โดยไม่จำกัดเพียงการยุติโพรเซส
ลำดับความสำคัญของโพรเซสด้วย nice, renice และสัญญาณ เป็นบทเรียน Linux Command Line Mastery ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Linux Command Line Mastery และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Beyond Starting and Stopping
You already know how to view processes with ps/top and stop them with kill. But sometimes a process should simply run more politely so it does not starve others of CPU.
That is what nice and renice are for.
What Is a Niceness Value?
Every process has a niceness from -20 (highest priority) to 19 (lowest priority). A nicer process yields CPU to others. Default is 0.
Starting a Process with nice
nice -n N command launches a command with niceness N. Higher numbers are friendlier to the rest of the system.
nice -n 10 tar -czf backup.tar.gz /var/logViewing Niceness
The NI column in top shows niceness. With ps you can request it explicitly.
ps -o pid,ni,comm -p 1Changing Priority with renice
renice adjusts the niceness of an already running process by PID.
renice -n 5 -p 1234Why You Need Root to Raise Priority
Any user can make a process nicer (raise the number). Only root can give a process a negative niceness, because that takes CPU away from everyone else.
sudo renice -n -5 -p 1234Signals: More Than kill
The kill command really sends a signal. SIGTERM (15) asks nicely to stop; SIGKILL (9) forces it; SIGHUP (1) often tells a daemon to reload config.
kill -lReloading Without Restarting
Sending SIGHUP to many services makes them re-read their configuration without a full restart, avoiding downtime.
kill -HUP 4567Pausing and Resuming a Process
SIGSTOP freezes a process and SIGCONT resumes it, handy for temporarily relieving load.
kill -STOP 4567
kill -CONT 4567Targeting by Name
pkill and killall let you send signals by process name instead of PID.
pkill -HUP nginxPutting It Together
A typical admin flow: spot a CPU hog in top, lower its priority with renice instead of killing it, and only escalate to kill -9 if it misbehaves.
renice -n 15 -p 8899 || kill -TERM 8899Quick Check
Which niceness value gives a process the highest CPU priority?
Recap
You learned to fine-tune process behavior:
nice -n N cmdstarts at a chosen priorityrenicechanges priority of running PIDs- Negative niceness needs root
- Signals like
SIGTERM,SIGHUP,SIGSTOP/SIGCONTcontrol processes without killing them
คำถามที่พบบ่อย
บทเรียน “ลำดับความสำคัญของโพรเซสด้วย nice, renice และสัญญาณ” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ลำดับความสำคัญของโพรเซสด้วย nice, renice และสัญญาณ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Linux Command Line Mastery ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ลำดับความสำคัญของโพรเซสด้วย nice, renice และสัญญาณ”
ควบคุมปริมาณ CPU ที่โพรเซสได้รับด้วย nice และ renice และเรียนรู้ว่าสัญญาณช่วยสื่อสารกับโพรเซสที่กำลังทำงานได้อย่างไร โดยไม่จำกัดเพียงการยุติโพรเซส คุณปฏิบัติ Linux Command Line Mastery ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Linux Command Line Mastery หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Linux Command Line Mastery บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “ลำดับความสำคัญของโพรเซสด้วย nice, renice และสัญญาณ” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Linux Command Line Mastery นี้ได้ไหม
ได้ บทเรียน Linux Command Line Mastery ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ทำความเข้าใจกระบวนการ: `ps`, `top`, `htop`
- การจัดการกระบวนการ: `kill`, `bg`, `fg`
- การตรวจสอบทรัพยากรระบบ: `df`, `du`, `free`
- ลำดับความสำคัญของโพรเซสด้วย nice, renice และสัญญาณ