Results 1 to 6 of 6

Thread: Launch a program from terminal for only 1 minute

  1. #1
    Join Date
    Aug 2011
    Beans
    19

    Launch a program from terminal for only 1 minute

    How can I launch a program from terminal and have it self-issue an x11-xkilsignal after one minute of operation?

  2. #2
    Join Date
    Oct 2011
    Location
    ZZ9 Plural Z Alpha
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Launch a program from terminal for only 1 minute

    Quote Originally Posted by IReadTheManual View Post
    How can I launch a program from terminal and have it self-issue an x11-xkilsignal after one minute of operation?
    Write a script?

    Code:
    program_name
    sleep 60
    kill -9 program_name

  3. #3
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,790
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Launch a program from terminal for only 1 minute

    Hi IReadTheManual.

    You cloud write a little script for it using job control.

    This is from the top of my mind: run the command in the background, wait a minute, and then kill it:
    Code:
    #!/bin/bash
    firefox &
    sleep 60
    kill %1
    I hope that points you in the right direction. Let's know how it goes.
    Regards.

  4. #4
    Join Date
    Feb 2007
    Beans
    863

    Re: Launch a program from terminal for only 1 minute

    Quote Originally Posted by cortman View Post
    Write a script?

    Code:
    program_name
    sleep 60
    kill -9 program_name
    you meant pkill? -9 can lead to disaster

    pkill and hup to target a given process are advised.

  5. #5
    Join Date
    Feb 2007
    Beans
    863

    Re: Launch a program from terminal for only 1 minute

    Quote Originally Posted by papibe View Post
    Hi IReadTheManual.

    You cloud write a little script for it using job control.

    This is from the top of my mind: run the command in the background, wait a minute, and then kill it:
    Code:
    #!/bin/bash
    firefox &
    sleep 60
    kill %1
    I hope that points you in the right direction. Let's know how it goes.
    Regards.
    You should really give better quality replies from forum staff.


    This code can be improved depending on your needs.

    Code:
    #!/bin/sh
    
    firefox "mypage" &
    
    sleep 1000
    for s in HUP INT KILL; do
        kill -$s $! &>/dev/null || break
        sleep 5
    done

    I advise:
    man sleep
    man pkill
    man kill

  6. #6
    Join Date
    Oct 2011
    Location
    ZZ9 Plural Z Alpha
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Launch a program from terminal for only 1 minute

    Quote Originally Posted by honeybear View Post
    you meant pkill? -9 can lead to disaster

    pkill and hup to target a given process are advised.
    kill -9 can lead to disaster? You do understand that the -9 flag simply means kill the process unconditionally, instead of sending a end process signal?
    This would depend on the user's needs- if he absolutely MUST have it stopped after one minute, kill -9 will deliver that every time.

    Quote Originally Posted by honeybear View Post
    You should really give better quality replies from forum staff.


    This code can be improved depending on your needs.

    Code:
    #!/bin/sh
    
    firefox "mypage" &
    
    sleep 1000
    for s in HUP INT KILL; do
        kill -$s $! &>/dev/null || break
        sleep 5
    done

    I advise:
    man sleep
    man pkill
    man kill
    First the OP specified sleep ONE MINUTE, not 1000 seconds as you've written. I advise: read the OP.
    I'm not sure that I understand the point of sending three different kill signals to the running program. Care to elaborate?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •