How to restart process running on Ubuntu 14.x version

I am new with Ubuntu. Please help me for this mentioned issue. This shaded area in attached image is my process that is running on Ubuntu 14.x version. It is python program which is reading a configuration file. When I am changing some configuration I always shut down "kill [process ID]" this process and start it. On new startup it takes new process ID.

Process Image

My client is non-technical guy he/she can not kill the process with changed ID and start it. I want such utility (command) that he/she can restart the process programmatically. what ever the process ID will be.

I have tried below thing:

sudo restart scheduler.py
sudo restart python3 scheduler.py
sudo scheduler.py restart
sudo python3 scheduler.py restart

All above tries are useless. Please help me

2 Answers

One way to achieve what you desire is as follows:

pkill scheduler.py
python3 /path/to/scheduler.py

You can also put it in a shell script.

To stop the process:

#!/bin/bash
pkill scheduler.py
exit 0

And save it as anyname1.sh

To start the process:

#!/bin/bash
python3 /path/to/scheduler.py
exit 0

Now, save it as anyname2.sh

Then, run this command to make them executable:

chmod +x /path/to/anyname1.sh
chmod +x /path/to/anyname2.sh

So, now, all your friend needs to do is double-click on those files and then click on Run.

EDIT: If the first script doesn't work as expected you may try this:

#!/bin/bash
kill -9 $(ps axf | grep scheduler.py | grep -v grep | awk '{print $1}')
exit 0
3

You can try the following commands in the terminal however it is highly recommended to just kill the service and restart it.

/etc/init.d/SERVICE_NAME restart

or

service SERVICE_NAME restart

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like