LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-27-2013, 08:23 AM   #1
santosh vyduyla
LQ Newbie
 
Registered: May 2013
Posts: 3

Rep: Reputation: Disabled
how to open application and after some time(time delay) automatically it should close


firefox | kill -9 `ps -A | grep firefox`

while using above command firefox opening and immediately it getting closed instead of that i need delay between opening and closing of application,i have alreay tried below command:
firefox | sleep 5 | kill -9 `ps -A | grep firefox`
 
Old 05-27-2013, 09:50 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by santosh vyduyla View Post
firefox | kill -9 `ps -A | grep firefox`

while using above command firefox opening and immediately it getting closed instead of that i need delay between opening and closing of application,i have alreay tried below command:
firefox | sleep 5 | kill -9 `ps -A | grep firefox`
What are you trying to accomplish with this? You're starting firefox, and wanting it to run for only 5 seconds before killing it?? What is the point/goal? And you can just put the commands in a shell-script, and execute them, if that's really what you want:
Code:
firefox &
sleep 5
kill -9 `ps -A | grep firefox`
 
Old 05-27-2013, 09:59 AM   #3
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Might the last line be replaced with the shorter "pkill -9 firefox" or are there possible problems with this?
 
Old 05-27-2013, 02:36 PM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Why do you need to "kill -9"? A simple kill should work and will allow the process to terminate cleanly (save existing state, etc.) rather than just terminating it abruptly. It might be best to make sure you get the correct firefox PID, just in case there are multiple copies running (e.g. using different user accounts. A generic script to do this would be something like:

Code:
#!/bin/bash

progtorun=$1

progtorun &
progpid=$!

sleep 30 # replace 30 with number of seconds to sleep

kill $progpid
sleep 5 # give it some time to die
kill -9 $progpid >& /dev/null # make sure it's dead.
Edit to add: you could make this script more robust by adding alarm signals in conjunction with wait to trap and see if the child process exits before the timer runs out. See this page for the basic idea.

Last edited by btmiller; 05-27-2013 at 02:39 PM. Reason: more info
 
Old 05-27-2013, 11:09 PM   #5
santosh vyduyla
LQ Newbie
 
Registered: May 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
problem resolved

Quote:
Originally Posted by TB0ne View Post
What are you trying to accomplish with this? You're starting firefox, and wanting it to run for only 5 seconds before killing it?? What is the point/goal? And you can just put the commands in a shell-script, and execute them, if that's really what you want:
Code:
firefox &
sleep 5
kill -9 `ps -A | grep firefox`
Santosh :just i want to write script which opens one application after another,but during that process first application should close before next application opens,hence i asked this question,anyway thanks your answer resolved my problem
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] The system time switches the time zone automatically but doesn't change the time RandomTroll Linux - Software 9 03-15-2013 12:28 PM
automatically open terminal at login time. gardenair Linux - Newbie 13 06-09-2011 10:13 PM
Mandriva 2007-open cd all the time automatically men123 Linux - Software 0 12-05-2006 01:55 PM
My computer restart automatically from time to time ?? pleasehelpme Linux - Newbie 2 07-04-2005 04:29 PM
System will automatically close my x server after a certain idle time. ICO Slackware 1 02-16-2004 11:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration