Linux shell script program to print the current process id

Here, we are going to learn how to print the current process id in Linux shell script?
Submitted by Nidhi, on February 14, 2021

Problem statement

Here, we will use the "$$" variable to print current process identifiers on the console screen.

Print the Current Process Id using Linux Shell Script

The source code to create a Linux shell script program to print the current process id is given below. The given program is compiled and executed successfully on Ubuntu 20.04.

Linux shell script program to print the current process id

#!/bin/bash

# Program name: "process_id.sh"
# Linux shell script program to print the current process id.
echo "Current process identifier: $$"

Now, we will save the shell script program with the "total_command.sh" name.

Output

$ sh process_id.sh 
Current process identifier: 3248

Explanation

In the above program, we used the $$ variable to get the current process identifier. After that, we printed the current process id on the console screen.

Linux shell script programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.