[Chicago-talk] system command to kill Xwindows session?

Jonathan Rockway jon-chicagotalk at jrock.us
Mon Mar 8 23:00:05 PST 2010


OK, so here are my thoughts on this issue.

 "startx" has way too much baggage for an automated process.  Do you
really want the X server to load, take over the screen and keyboard, and
wait for default system window manager (like a full GNOME session) to
load... or do you just want to run some script that requires an X
server?

In the first case, sure, use startx.  But isn't the user going to be
confused when the X server randomly dies without saving his session?

If you just want an interactive Xserver, though, just run "X :1" or
whatever, and then set DISPLAY to ":1".  When you don't want X anymore,
just send it SIGTERM or whatever.

But in most cases, you don't actually need a real Xserver that touches
the hardware; you can just use Xvfb and connect your clients to that.
Then there is no interference with the host machine.

http://en.wikipedia.org/wiki/Xvfb

Any time I have ever needed an X server for an automated process, Xvfb
has been what I've needed.  It works like a real X server, except it
doesn't touch the real hardware.

Finally, stop fighting with hacks around system and qx.  If you need to
start a real background process, use a module like AnyEvent::Subprocess:

   my $done = AnyEvent->condvar;
   my $job = AnyEvent::Subprocess->new(
       code          => [qw/Xvfb :1234/],
       on_completion => sub { say 'X server exited with status '. $_[0]->exit_status },
   );

   my $proc = $job->run;
   $ENV{DISPLAY} = ':1234';
   <interact with the X server>;
   $proc->kill('TERM');

Much cleaner.

Regards,
Jonathan Rockway

* On Sun, Mar 07 2010, Richard Reina wrote:
> Linux.  Sorry.
> ---- Chicago.pm chatter <chicago-talk at pm.org> wrote:
>>
>> You didn't telll me if you are on UNIX.
>>
>> The "startx" script has to give you the PID, which it currently isn't doing,
>> and then you have to gather the PID.
>>
>> In "startx", assuming Unix
>>
>> 	$!/bin/ksh
>> 	Foobar &
>> 	echo $!
>>
>> I assume you are using the '&' to background "Foobar".  The '$!' gives you
>> pid of background job, but must be immediately following "Foobar &" command.
>>
>> In Perl, you gather the echoed PID by using "qx" instead of system()
>>
>> my $thePid = qx/startx/;
>>
>> Now you can kill $thePid.
>>
>> Got to go.  Goodluck, bye.
>>
>> Alexander
>>
>> -----Original Message-----
>> From: chicago-talk-bounces+danel=speakeasy.net at pm.org
>> [mailto:chicago-talk-bounces+danel=speakeasy.net at pm.org] On Behalf Of
>> Richard Reina
>> Sent: Sunday, March 07, 2010 10:06 AM
>> To: Chicago.pm chatter
>> Subject: Re: [Chicago-talk]system command to kill Xwindows session?
>>
>> I have script that starts an xwindows session with system("startx") I want
>> it to end as soon as a specific tast is done?
>>
>>
>> ---- Chicago.pm chatter <chicago-talk at pm.org> wrote:
>> >
>> > Your question is incoherent; obviously if you are looking for a system
>> > command, then its not a Perl function.
>> >
>> > How did you start the process that opened the window, and are you willing
>> to
>> > kill the entire process?
>> >
>> > On Unix, if you know the process-id, then try:
>> >
>> > 	system("kill TERM $thePid");
>> >
>> > Alexander
>> >
>> > -----Original Message-----
>> > From: chicago-talk-bounces+danel=speakeasy.net at pm.org
>> > [mailto:chicago-talk-bounces+danel=speakeasy.net at pm.org] On Behalf Of
>> > Richard Reina
>> > Sent: Sunday, March 07, 2010 9:18 AM
>> > To: chicago-talk at pm.org
>> > Subject: [Chicago-talk] system command to kill Xwindows session?
>> >
>> > Does anyone know if there is a perl fucntion or a command that can be put
>> > into system("") that will kill Xwindow and return a script/user to the
>> > console?
>> >
>> > Thanks,
>> >
>> > Richard
>> > _______________________________________________
>> > Chicago-talk mailing list
>> > Chicago-talk at pm.org
>> > http://mail.pm.org/mailman/listinfo/chicago-talk
>> >
>> > _______________________________________________
>> > Chicago-talk mailing list
>> > Chicago-talk at pm.org
>> > http://mail.pm.org/mailman/listinfo/chicago-talk
>> >
>> _______________________________________________
>> Chicago-talk mailing list
>> Chicago-talk at pm.org
>> http://mail.pm.org/mailman/listinfo/chicago-talk
>>
>> _______________________________________________
>> Chicago-talk mailing list
>> Chicago-talk at pm.org
>> http://mail.pm.org/mailman/listinfo/chicago-talk
>>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk

--
print just => another => perl => hacker => if $,=$"


More information about the Chicago-talk mailing list