Linux Processes

A process is a program or a task which is in the state of execution. When you open a application like `Chrome`, `VSCode`, etc., the operating system creates a process. The running processes can be viewed from the command line using simple commands like `ps`.

Linux Processes

A process is an instance of running a program. If, for example, three people are running the same program simultaneously, there are three processes there, not just one. In fact, we might have more than one process running even with only person executing the program, because (we will see later) the program can split into two, making two processes out of one.

Keep in mind that a Linux commands, e.g. cc and mail, are programs, and thus contribute processes to the system when they are running. If 10 users are running mail right now, that will be 10 processes. At any given time, a typic Linux system will have many active processes, some of which were set up when the machine was first powered up.

Every time we issue a common Linux starts a new process, and suspends the current process (the C-shell) until the new process completes (except in the case of background processes, to be discussed later Linux identifies every process by a Process Identification Number (pid) which is assigned when the process is initiated.

When we want to perform an operation on a process, we usually refer to it by its pi Linux is a times haring system, which means that the processes take turns running.

Each turn is a called a time-slice, on most systems this is set at much less than one second. The reason this turns-taking approach is used is fairness: We don’t want a 2-second job to have to wait for a 5-hour job to finish, which is what would happen if a job had the CPU to itself until it completed.1

Foreground/Background Processes

Suppose we want to execute a command but do not want to wait for its completion, i.e. we want to be able to issue other commands in the meantime. We can do this by specifying that the command be executed in the background.

There are two ways to do this. The first is to specify that it be a background process when we submit it, which we can do by appending an ampersand (`&’) to the end of the command. For example, suppose we have a very large program, which will take a long time to compile. We could give the command

cc bigprog.c &

Which will execute the compilation while allowing me to submit other commands for execution while the compiler is running. The C-shell will let me know what the pid is for this background process (so that we can later track it using ps, or kill it), but will also give me my regular prompt, inviting me to submit new commands while the other one is running.

Processes and Jobs

A process is an executing program identified by a unique PID (process identifier). To see information about wer processes, with their associated PID and status, type

ps

A process may be in the foreground, in the background, or be suspended. In general the shell does not return the UNIX prompt until the current process has finished executing. Some processes take a long time to run and hold up the terminal. Back grounding a long process has the effect that the UNIX prompt is returned immediately, and other tasks can be carried out while the original process continues executing.

Subscribe For More Content