LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 09: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, 10:50 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,961

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
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, 10:59 AM   #3
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 6,030

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

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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 03:39 PM. Reason: more info
 
Old 05-28-2013, 12:09 AM   #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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:28 PM
automatically open terminal at login time. gardenair Linux - Newbie 13 06-09-2011 11:13 PM
Mandriva 2007-open cd all the time automatically men123 Linux - Software 0 12-05-2006 02:55 PM
My computer restart automatically from time to time ?? pleasehelpme Linux - Newbie 2 07-04-2005 05:29 PM
System will automatically close my x server after a certain idle time. ICO Slackware 1 02-16-2004 12:26 PM


All times are GMT -5. The time now is 08:43 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration