LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-16-2014, 05:00 PM   #1
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Rep: Reputation: 4
is there a way to execute a script after X terminates?


when X start .xinitrc executes.
Is there a script executed after X ends or terminates?
 
Old 07-17-2014, 03:30 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,874
Blog Entries: 13

Rep: Reputation: 4928Reputation: 4928Reputation: 4928Reputation: 4928Reputation: 4928Reputation: 4928Reputation: 4928Reputation: 4928Reputation: 4928Reputation: 4928Reputation: 4928
None that I can think of directly; however there are things like services which have scripts arranged to restart, reload, or force-reload but they need to be triggered by an event.

What I've done is something like a program which forks a child, the child uses a form of exec to run the command, and the parent waits on the child for signals; one of which is termination, at which point the parent can then cause a restart or reload, or whatever other action you're desiring.

This may be way beyond what you were thinking of. Perhaps you can relate why you wish to do this and what you intend to do so, and maybe what you wish to accomplish is do-able via some other means.
 
Old 07-17-2014, 05:47 PM   #3
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Original Poster
Rep: Reputation: 4
In the terminal I wanted LANG env variable to be en_US
cuz I can't read other language other than english.
and error msg in other than english is meaningless and can't be read.
In X I want set LANG to be ko_KR.UTF-8. so I can read.
so I can set LANG to be en_US in .bash_profile then put ko_KR.UTF-8
in .xinitrc. but the problem was how to set LANG back to en_US when
X terminates. but problem solved. when i did above, when X was
terminated, mysteriously my LANG variable set back to en_US.
Still don't why and how it worked. Can someone provide the answer?
 
Old 07-17-2014, 05:58 PM   #4
maples
Member
 
Registered: Oct 2013
Location: IN, USA
Distribution: Arch, Debian Jessie
Posts: 814

Rep: Reputation: 265Reputation: 265Reputation: 265
What if you just added it to the bottom of your .xinitrc? Like this:

Code:
...

exec (your desktop environment's start command, like "startxfce4" or something)

(code to be run after you close X)
I've never tried anything like this, so it may or may not work...
 
Old 07-20-2014, 07:15 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Nothing runs that follows an "exec" unless the exec fails...

You have to remove the "exec". That way the shell waits until the command terminates.


But your problem will not be fixed.

The way the .xinitrc is used different than what you think:

1. startx (assuming that is the way X is started)
2. Xserver (started by startx with keys).
3. startx starts .xinitrc with the DISPLAY environment variable set.
4. .xinitrc starts a window manager (or whatever process used to access the GUI).


Thus, if the Xserver aborts or gets terminated in some way, no commands in .xinitrc will be processed.

The Xserver only exits when the .xinitrc (or whatever inherits the PID) terminates. If the Xserver terminates first, the all the child processes are terminated by startx. Specifically, the X server terminates when the last GUI connection terminates... That is why the "exec <window manager of choice>" is the last line executed.

If you do want a wrapper, then it must be around the startx command. Unfortunately, this doesn't work for GUI based logins. There IS a script that can be run (depending gdm/kdm/xdm to run it) that is used for some cleanup.

The original sequence is/was (see http://www.x.org/archive/X11R6.8.1/doc/xdm.1.html for this. It doesn't seem to have changed since):

1. Xsetup script - used to control access to hardware, this script was to make sure the hardware worked, and runs as root, and initializes things for the login window.
2. Xstartup script - may be used to control access to other resources, the user has logged in, but this script runs as root (at one time, this was where access to audio devices was controlled).
3. Xsession script - used to start the users session - it runs as the user, note: the X server is already running. It is this script that runs the users .xsession file (if it exists).
4. reset script - used to take back access to hardware, this script was to ensure the user is cut off from the resources granted by the startup script, and also runs as root.

If you don't mean to run things after the X server aborts, then what you are referring to is either the .xinitrc or .xsession file. This file has (usually) a last line "exec <window manager of choice>", or in case of various other implementations, this is the LAST LINE EXECUTED BY THE SHELL SCRIPT (which may not be the last line of the script). If the "exec" part is removed, then other commands can be executed after the window manager exits.

Last edited by jpollard; 07-20-2014 at 07:19 AM.
 
Old 07-20-2014, 09:43 AM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by babbab View Post
but problem solved. when i did above, when X was
terminated, mysteriously my LANG variable set back to en_US.
Still don't why and how it worked. Can someone provide the answer?
Just a guess, your login shell set the LANG to us, then starts the xinitrc script, so xinitrc is a child process of login shell

You can try this on console:

Code:
export LANG=en_US
sh
export LANG=ko_KR.UTF-8
echo $LANG
exit
echo $LANG
sh shell was a child process
 
  


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] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 02:27 PM
initiation script terminates webpage ted_chou12 Linux - Newbie 0 02-16-2011 12:03 PM
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 03:41 AM
shell script terminates as zombie, ie, <defunct> Kropotkin Linux - Newbie 3 02-20-2007 01:15 AM
How do I keep an executable from terminates after the initiating shell terminates mr.v. Linux - Newbie 8 01-20-2007 03:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:05 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
Open Source Consulting | Domain Registration