Kuk Linux 2023

Kuk Linux 2023

Kuk Linux 2023

Q7(a) :- What is process? Write command to view all the process in system including hidden process, stop a particular process, sending background to foreground and foreground to background process.

Processes in Linux

A process in computing is an instance of a running program. It encompasses the program code and its current activity, including its execution state, memory usage, and resource allocations. Processes are fundamental to the functioning of an operating system, enabling multitasking by allowing multiple programs to run simultaneously.

Each process in a Unix-like operating system, such as Linux, is uniquely identified by a Process ID (PID). Processes can be in various states, such as running, waiting, stopped, or terminated. The operating system manages these processes through a scheduler, which allocates CPU time and other resources.

Processes can be created by the system or by other processes. The fork system call is commonly used to create a new process, known as a child process, which is a duplicate of the parent process. After forking, the exec system call can be used to replace the child process’s memory space with a new program.

Processes are categorized into different types based on their role and behavior:

  • Foreground Processes: These are processes that interact with the user via a terminal. They can be controlled directly using the terminal interface.
  • Background Processes: These run without user interaction, typically performing tasks like system monitoring or scheduled jobs.

Viewing Processes

To view all processes in the system, including hidden ones, the ps and top commands are typically used.

  1. ps Command: The ps command is used to display information about active processes. To see all processes, including those without a controlling terminal (which are often considered “hidden”), you can use the following command:

ps aux

htop Command: An enhanced version of top, which provides a more user-friendly interface.

htop

Stopping a Process

To stop a particular process, you use the kill command followed by the PID of the process. To find the PID, you can use ps or top.

1. kill Command: Sends a signal to a process to terminate it. The default signal is SIGTERM (signal 15), which requests the process to stop gracefully. If the process does not stop, you can send SIGKILL (signal 9) to force it to stop immediately.

kill PID

2. killall Command: Terminates all processes by the specified name.

killall process_name

Moving Processes Between Foreground and Background

In a Unix-like operating system, processes can be run in the foreground or the background.

1. Running a Process in the Background: You can start a process in the background by appending an & at the end of the command.

command &

2. Bringing a Background Process to the Foreground: If a process is running in the background, you can bring it to the foreground using the fg command.

If there are multiple background jobs, specify the job number:

fg %job_number

Sending a Foreground Process to the Background: If a process is running in the foreground, you can suspend it by pressing Ctrl+Z and then move it to the background using the bg command.

If there are multiple background jobs, specify the job number:

fg %job_number

Q7(b) :- What is signal and write signal of rc, stopping the process and priority?

Signals in Linux

In Linux, a signal is a limited form of inter-process communication used to notify a process that a particular event has occurred. Signals are asynchronous notifications sent to a process or to a specific thread within a process to prompt a predefined action or to handle exceptional situations. Processes can handle signals in different ways: ignoring them, catching and handling them via signal handlers, or performing the default action. For instance, handling SIGTERM allows a process to clean up resources before exiting. Signals are categorized into standard signals and real-time signals. Each signal type has a specific purpose and behavior. 1. Standard Signal :- Standard signals have predefined purposes and behaviors, which are consistent across different Unix-like systems 2. Real Time Signal:-Real-time signals (SIGRTMIN to SIGRTMAX) provide a way to queue multiple signals. They are used for real-time processes and have higher priority than standard signals.

Write Signal of re

To write or send a signal to a process in Linux, you can use the kill command or the kill function in code. The kill command is used to send signals to processes by specifying their PID (Process ID). For example, to send a SIGTERM signal to a process with PID 1234:
kill -TERM 1234

Stopping a Process

  • Stopping a process in Linux refers to the act of pausing the execution of a process, effectively freezing its state so that it no longer consumes CPU time. This is different from terminating a process, which ends it permanently. Stopping a process is useful for temporarily freeing up system resources or for debugging purposes, allowing a user to pause and inspect the process state without terminating it.Stopping a process can be achieved using signals, specifically SIGSTOP and SIGTSTP.

     
    • SIGSTOP: This signal stops the process unconditionally. The process cannot catch or ignore this signal. It is akin to pausing the process completely.

    • SIGTSTP: This signal is typically sent when the user types Ctrl+Z in the terminal. Unlike SIGSTOP, a process can catch and handle SIGTSTP.

    A stopped process can later be resumed with the SIGCONT signal, which allows it to continue execution from where it was paused.

    Example:

kill -STOP <PID>
  • Process Priority

  • Process priority in Linux determines how much CPU time a process receives. There are two key concepts:

    1. Nice Value: It ranges from -20 (highest priority) to 19 (lowest priority). You can set the nice value of a process using the nice and renice commands.

      • To start a process with a specific nice value:

nice -n 10 command
  •      2. Real-Time Priority: Real-time processes have higher priority than normal processes.              These can be managed using chrt.

    •           To set a real-time priority:
chrt -r -p 20 1234
  • Here, 20 is the priority, and 1234 is the PID. Real-time priorities range from 1 (lowest) to 99 (highest).

Scroll to Top