60
Views

I created a small script a while back because I had an application that had some known issues relating to starting again after Wi-Fi had reconnected. So I would have to kill the app and start it again. Rather than go to the app, each time, kill it and then restart it, I created a quick script that I mapped to a function key that would do this for me.

The Script

#!/bin/bash
var=$(ps ax | grep owncloud)
process=${var:0:5}
kill -HUP $process
owncloud &

This section finds the process details and sets the information as the variable “var” in the script.

var=$(ps ax | grep owncloud)

Here is the output.

get-proccess-details

You will notice that the first five characters are ” 4254″ which is the process ID for ownCloud. We will use this id in the next line. Notice that I counted the space before the 4 because the next line will take that into account.

process=${var:0:5}

This line will take the first five characters from the variable “var” that was set in the previous line. Again, this is the process ID for ownCloud.

Next, we will kill the process that we have isolated as the variable “process” in the previous step. This is the command to do that.

kill -HUP $process

Finally, we start the application again. We use the “&” after the application name to start it independent of the terminal as it’s own process.

owncloud &

Another Example

This process could be used with any application or process. You would just replace “owncloud” with the application name. Here is any example of restarting FireFox.

#!/bin/bash
var=$(ps ax | grep firefox)
process=${var:0:5}
kill -HUP $process
firefox &

Conclusion

The scripting of a process reset is just a small piece of a bigger picture. This snippet could be used in a bigger script that would require a process reset.

Let me know if you have questions or want to share your use of the script in the comments below.

Article Tags:
Article Categories:
Coding
SDATIC

Web developer and former photographer by trade...gamer and all around tech enthusiast in his free time. Christoph started sdatic.com as a way to organize his ideas, research, notes and interests. He also found it enjoyable to connect and share with others who parallel his interests. Everything you see here is a resource that he found useful or interesting and he hopes that you will too.

Leave a Reply

Your email address will not be published. Required fields are marked *