মূল কন্টেন্টে যান
eLearner.app
মডিউল 5 · 2-এর পাঠ 2কোর্সে 11/11~15 min
মডিউল পাঠ (2/2)

কাজের নিয়ন্ত্রণ এবং লগ (বিজি, এফজি, টেল)

When using the terminal, you might want to run a long-term command without locking up the shell. Linux supports Job Control, which allows you to send processes to the background and switch them back to the foreground. In addition, you will learn how to monitor logs to check what is happening on the system.


Running Commands in the Background: & and jobs

To start a command directly in the background (releasing control of the terminal immediately), append the & (ampersand) character to the end of the command:

Bash
sleep 1000 &

This command returns a job number (e.g., [1]) and a PID.

Listing Jobs: jobs

The jobs command lists the active processes associated with the current shell session that are running in the background or suspended:

Bash
jobs

Moving Processes: fg, bg, and Ctrl+Z

If a command is running in the foreground and blocking the terminal, you can:

  1. Press Ctrl + Z to suspend (pause) the current process.
  2. Use the bg (background) command to restart the suspended process in the background:
    Bash
    bg %1   # Restarts job 1 in the background
  3. Use the fg (foreground) command to bring a background process back to the foreground:
    Bash
    fg %1   # Brings job 1 to the foreground

Monitoring Logs: tail and journalctl

System and application logs record important events. Often, you need to observe these files in real-time as they are being written.

Viewing the End of a File: tail

The tail command displays the last lines of a file (default is 10 lines):

Bash
tail /var/log/syslog
tail -n 20 /var/log/syslog    # Shows the last 20 lines

To monitor a file in real-time (for example, to see log messages generated while testing an application), use the -f (follow) option:

Bash
tail -f logs/server.log

Try it yourself

Exercise 1: List active jobs

ব্যায়াম#linux.m5.l2.e1
প্রচেষ্টা: 0লোড হচ্ছে...

Display the list of current jobs (background or suspended processes) in the terminal session using the 'jobs' command.

সম্পাদক লোড হচ্ছে...
ইঙ্গিত দেখান

Use simply the 'jobs' command.

সমাধান 3 প্রচেষ্টার পরে উপলব্ধ

Exercise 2: Bring a job to the foreground

ব্যায়াম#linux.m5.l2.e2
প্রচেষ্টা: 0লোড হচ্ছে...

Bring the currently active background job to the foreground using the 'fg' command.

সম্পাদক লোড হচ্ছে...
ইঙ্গিত দেখান

Use the 'fg' command to bring the job back to the foreground.

সমাধান 3 প্রচেষ্টার পরে উপলব্ধ

Exercise 3: Check the last lines of a log

ব্যায়াম#linux.m5.l2.e3
প্রচেষ্টা: 0লোড হচ্ছে...

Display the last lines of the log file located at 'logs/server.log' using the 'tail' command.

সম্পাদক লোড হচ্ছে...
ইঙ্গিত দেখান

Use 'tail' followed by the file path: 'logs/server.log'.

সমাধান 3 প্রচেষ্টার পরে উপলব্ধ