This article will show you how.

What Is aBash Process?

A Bash process is simply an executable which is running.

Terminal window showing the manual page for the Mutt email client on Linux

For example, when you start the calculator in your desktop environment, a Bash process is created.

In summary, thePIDholds a number based unique ID for a given running app (i.e.

process), whereas thePPIDfor any given running tool (i.e.

Four hard drivers sticking out of a rack-mount server that’s being used as a NAS.

process) stores theParent PIDof the process which started this new app, hence the term ‘Parent’.

Next, we terminated it with a signal 9killcommand.

Replace$RELEVANT_PIDin the code with the PID reported bypsif you try this code.

Article image

Note that the background process is immediately terminated by thekill -9instruction.

And, it will only do so when that notification is inline with existing work, i.e.

it is more pull-based then push-based.

Root processes on Linux

Returning to ourkill command, a signal 9killis one of the most destructive kills there is.

It basically terminates the program on the spot without being nice about it.

For the purposes of this article, we will usesignal 9to always immediately and effectively terminate a process.

A simple process kill in Linux

However, even when using asignal 9kill/process termination, sometimes a process may linger around in adefunctstate.

That is where the similarity ends.

We see that only a singlePIDis returned, which matches the fact that we have only a singlegnome-calculatorstarted.

More well defined process termination in Linux

Our final command adds anxargscommand with akill -9instruction to terminate our process(es).

Note that xargs is prefixed by a pipe itself.

Though the possibility of this occurring is small, it is possible.

Excluding owned processes from a process termination command

Working these things into our command looks better, but it’s not perfect yet.

What is this is a server with 10 users and all 10 have started a calculator?

Thewhoamicommand will return to the terminal the current logged in users.

A safer version or a multi-process termination command

We now terminate only our own owned processes.

No, regrettably errors are still possible even with such a detailed tuned command line.

For example, if the process list contains locale or odd characters, ourgrepmay potentially still fail.

Example of a killall command excution

Finally, we inserted an additionalgrep -owith a regular expression that searches for the numbers0-9only.

Thekillallcommand also allows you to set options like–userto only kill processes the specified user owns etc.