You are not logged in.

#1 2014-09-11 01:19:09

mwarner
Member
Registered: 2014-09-08
Posts: 5

Running a shell script outside of Xorg?

I'm pretty new to linux so bear with my limilted knowledge big_smile

I wrote a simple shell script to switch between the intel and nvidia graphics in my optimus enabled laptop(bumblebee performance wasn't quite as good as the real thing). Basically it shuts down the display manager, moves some symlinks around, loads/unloads drivers, then fires gdm up again. It works perfectly from a terminal (CTRL+ALT+F2), however I can't launch it from inside an Xorg session as the first thing the script does is kill off that session....is there anyway around this? Is there someway to launch a script independant of the Xorg session so I just click a shortcut and a few seconds later I'm back in Xorg on the other video card?

Last edited by mwarner (2014-09-11 01:19:20)

Offline

#2 2014-09-11 01:45:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: Running a shell script outside of Xorg?

The most direct answer to your initial question is to use setsid and/or nohup.  The script is killed as it's parent process gets killed.  setsid reparents it to PID 1, so it never gets the SIGHUP while nohup just makes it ignore the SIGHUP.

But a much cleaner way of doing this would be to just launch it from PID 1 in the first place: make a systemd service file for it.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2014-09-11 04:38:05

mwarner
Member
Registered: 2014-09-08
Posts: 5

Re: Running a shell script outside of Xorg?

Thanks Trilby, systemd is a perfect solution! I've now got a working solution that lets me switch cards with the click of a button big_smile

Offline

#4 2014-09-11 08:57:43

Awebb
Member
Registered: 2010-05-06
Posts: 6,688

Re: Running a shell script outside of Xorg?

Wise men say: He who marks his topics as solved does not attract helpers for nothing.

Offline

Board footer

Powered by FluxBB