Difference between revisions of "Template:Check PID running"

From wikieduonline
Jump to navigation Jump to search
(Created page with "<pre> #!/bin/bash if [ $# -eq 0 ] then echo "Usage: $0 <process PID>" echo "Checks if a process is running by its PID." exit 1 fi # Get the PID of the process to...")
 
 
Line 1: Line 1:
<pre>
+
#!/bin/bash
#!/bin/bash
+
 
+
if [ $# -eq 0 ]
if [ $# -eq 0 ]
+
then
then
+
    echo "Usage: $0 <process PID>"
    echo "Usage: $0 <process PID>"
+
    echo "Checks if a process is running by its PID."
    echo "Checks if a process is running by its PID."
+
    exit 1
    exit 1
+
fi
fi
+
 
+
# Get the PID of the process to check from the command line argument
# Get the PID of the process to check from the command line argument
+
process_pid=$1
process_pid=$1
+
 
+
# Check if the process is running
# Check if the process is running
+
if [[ps -p]] $process_pid > /dev/null
if ps -p $process_pid > /dev/null
+
then
then
+
    echo "Process with PID $process_pid is running."
    echo "Process with PID $process_pid is running."
+
else
else
+
    echo "Process with PID $process_pid is not running. Running tput bel..."
    echo "Process with PID $process_pid is not running. Running tput bel..."
+
    while true; do [[tput bel]]; sleep 1; done
    while true; do tput bel; sleep 1; done
+
fi
fi
 
</pre>
 

Latest revision as of 15:42, 30 March 2023

#!/bin/bash

if [ $# -eq 0 ]
then
    echo "Usage: $0 <process PID>"
    echo "Checks if a process is running by its PID."
    exit 1
fi

# Get the PID of the process to check from the command line argument
process_pid=$1

# Check if the process is running
if ps -p $process_pid > /dev/null
then
    echo "Process with PID $process_pid is running."
else
    echo "Process with PID $process_pid is not running. Running tput bel..."
    while true; do tput bel; sleep 1; done
fi

Advertising: