Answer the question
In order to leave comments, you need to log in
What is the difference between ps axu and ps cax?
I want to make it so that when my telegram bot crashes, it starts automatically again. Started writing a bash script. First you need to check if such a process is running. I wanted to do it like this:
#!/bin/bash
bot_pid=`cat /home/vladimir/bot_dir/pid.txt`
echo $bot_pid
ps axu | grep $bot_pid
if [ $? == 0 ]; then echo "Bot is working"
elif [ $? == 1 ]; then echo "Bot is dead"
fi
Answer the question
In order to leave comments, you need to log in
Actually, it's better to do this through systemd
PS: A short googling shows that you can find out if a process with a given pid is running with the command
0 - it works (returns a command), 1 - there is no such process
ps -p $bot_pid -o comm=
man ps
is it really that hard to find out what the c and u options do?
one outputs the entire command, the other is user-oriented
But in general, if you already have a PID file, then it's better
ps -p $(cat /home/vladimir/bot_dir/pid.txt)
if [ $? == 0 ]; then echo "Bot is working"
elif [ $? == 1 ]; then echo "Bot is dead"
fi
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question