Shut down a specified process after the system is idle for a period of time

Source: Internet
Author: User

Principle: Use the screen in Ubuntu to protect the status of the process (gnome-screensaver-command-q) (its principle is to automatically lock the screen after the system is idle for a certain period of time ), determines that the computer is idle and executes a specificProgram.

 #  ! /Bin/sh  
# This program is used to end the specified program after a certain period of time.
# /Usr/bin/mentohust-K can also be used to end the mentohust Process

Taskkill ()
{
If [$ # -Ne 2]; then
PID = $ (PS ax | grep $1 | Awk '{ If ( $0 !~ /Grep/) {print $1 }}')
# Echo "pid = $ PID"
If [-N " $ PID " ]; Then
Kill-9 $ PID >/Dev/null 2> & 1
Fi
Return 0
Fi
# Echo "Num: $"
Return 1
}

Process = " Mentohust "
SSN = " The screen saver status is inactive. "
SSA =" The screen saver status is active. "
Log = " /Tmp/taskkill. Log $ "

While :
Do
State = $ (gnome-screensaver-command-Q 2>/dev/null)
If [ " $ State " = " $ SSA " ]
Then
Taskkill $ Process
Break
Else
Echo " The Screen Saver is still not active " $ (Date)> $ Log
Sleep 300
Fi
Done
Echo " Screen Saver active! At " $ (Date)> $ Log

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.