Borealis
Borealis

Reputation: 8470

How to check on screen background script processes?

I have a shell script running in the background on a AWS server. To get there, I used the following commands:

apt-get install screen   #Install screen
screen -m                #Start screen
bash myscript.sh         #Run the script
CTRL + a and then d      #Detach and run in background

To check on the script to see if it is still running, I use the following commands:

# List the detached screens
screen -ls

# Find the screen to reattach and attach
screen -r 123456

Is there a more elegant way to see if my background script is still running and not hung or in an error state?

Upvotes: 1

Views: 116

Answers (1)

Samuel
Samuel

Reputation: 3801

You can use pgrep <process_name> to check if your scrip is still running.

pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout. All the criteria have to match.

http://linux.die.net/man/1/pgrep

Upvotes: 1

Related Questions