LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 06-23-2011, 01:42 PM   #1
pponnath
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
Post how to close "any" application cleanly from command line


My Redhat release: CentOS release 5.3 (Final)
Question:
Sometimes i open so many 'nedit'(editor application) windows and i have to close all of them one by one. I want to close all of them from the command line. But i donot want to use 'kill' since that will forcibly terminate without saving the file(if i want to).
Is there any way we can run from command line to close an application but prompting me to save if it is not saved.
In short, i want a command line equivalent of 'moving the mouse and clicking 'X' on the window
 
Old 06-23-2011, 02:25 PM   #2
bhaslinux
Member
 
Registered: Oct 2003
Location: UnitedKingdom
Distribution: Debian Bullseye
Posts: 357

Rep: Reputation: 49
xprop gives the PID of that process

you can send a HUP to that PID. But the process of exiting an application gracefully is totally application dependent and is handled by each application in its own manner. Many do not support HUP signals and it will just crash the program. Some others will respond to USR1 signal.

_NET_WM_PID is the xprop which gives the PID of that running process
 
Old 06-23-2011, 03:21 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can try wmctrl. It can send a graceful close command to X applications. The only problem is that it select open X applications based on the window title, not on the application name. Luckily you can modify the appearance of the windows title in the Nedit preferences, so that a uniquely identified string can be a valid fingerprint for the application you want to close.

In Nedit go to Preferences --> Default Settings --> Customize Window Title. In the Format box you can write any string. For example if you choose:
Code:
Nedit: {%c} [%s] %f (%S) - %d
it will show the default window title preceded by the string Nedit:. Save the defaults to make this behavior permanent.

Now to quit a nedit X window you can do
Code:
wmctrl -c Nedit
Unfortunately wmctrl does not have a recursive option, so that it can close only one window. If you want to close multiple nedit session at once, you can define a function like this:
Code:
xquit () 
{ 
    for n in $(wmctrl -l | awk -v name=$1 '$0 ~ name{print $1}');
    do
        wmctrl -i -c $n;
    done
}
this will loop over all the windows having a specific title. The command:
Code:
xquit Nedit
now will close all the sessions and will ask to save modified files (if any). Hope this helps!
 
Old 06-23-2011, 04:19 PM   #4
pponnath
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks for the reply.

I donot find wmctrl as part of redhat release that i have.
 
Old 06-23-2011, 04:44 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It is provided by the RPMforge repository (direct download here).
 
Old 06-23-2011, 06:18 PM   #6
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
you can use < ctlr> + <c>
that will kill the current running command
 
  


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] How do I run "menu" and "logout" from the command line in fluxbox? psionl0 Slackware 19 03-02-2011 12:46 AM
[SOLVED] Application close, minimize and maximize on the "other" side... Joachim Schrader Linux - Laptop and Netbook 4 05-11-2010 08:26 AM
How can I start "Application Browser" from the command line? ggyyree Linux - Newbie 5 11-09-2009 04:09 PM
When "not cleanly unmounted", why the "check forced" is not not applied at boot? frenchn00b Debian 1 09-06-2009 11:21 AM
Opening "Application Launcher" from command line -- KDE 4.1 andrems Linux - Desktop 3 09-09-2008 05:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 06:35 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