Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 37

Thread: [SOLVED] Turning off Compiz for Games Script

  1. #21
    Join Date
    Nov 2007
    Location
    india
    Beans
    485
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Turning off Compiz for Games Script

    Quote Originally Posted by anotherdisciple View Post
    So, I tried...
    Code:
    a=`ps -fp $$ |tail -1 | awk '{print $3}'`
    kill $a
    and it didn't work... I even ran it in a script by itself... and I tried killall instead of kill. But that was pretty clever... I wouldn't have thought about the id.

    However I tried running a script that just slept for 3 second and did a killall gnome-terminal... it worked. Here is the final script if anyone wants to use it...

    Code:
    #!/bin/bash
    
    read -p "What game would you like to play?" GAME
    metacity --replace &
    sleep 3
    $GAME
    compiz --replace &
    sleep 3
    killall gnome-terminal

    your "solution" script has a BIG flaw, when you issue :
    Code:
    killall gnome-terminal
    it will kill ALL the gnome-terminals you are currently running...and i dont think you would want this.
    thats why i used ppid, so that only the present terminal is closed.
    to make things more complex, i have to use the pppid now, ie, the pid of the command's (to find the pid) parent 's (this shell script) parent (the terminal).
    so here is the final code :
    Code:
    #!/bin/bash
    read -p "What game would you like to play?" GAME
    metacity --replace &
    $GAME
    compiz --replace &
    a=`ps -fp $$ |tail -1 | awk '{print $3}'`
    b=`ps -fp $a | tail -1| awk '{print $3}'`
    kill $b
    exit
    one more thing about your script...the exit status of your script is 1 - and this technically means that your script isnt yet perfect.
    i am also keen to know what purpose does 'sleep' solve for you ??

  2. #22
    Join Date
    Feb 2007
    Location
    Germany, Nuremburg
    Beans
    1,019
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Turning off Compiz for Games Script

    Quote Originally Posted by dexter.deepak View Post

    one more thing about your script...the exit status of your script is 1 - and this technically means that your script isnt yet perfect.
    i am also keen to know what purpose does 'sleep' solve for you ??
    who cares? as long this script will stay a single peace of "art", it doesn't matter at all. (At least I think so)
    Edit: I have RadeonHD 3870 factory OC
    ... put your money where your mouth is ...
    stop sustaining Microsoft (and its pet named Apple)!
    Use the Thanks-button if you feel like!

  3. #23
    Join Date
    Nov 2007
    Location
    india
    Beans
    485
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Turning off Compiz for Games Script

    Quote Originally Posted by soxs View Post
    who cares? as long this script will stay a single peace of "art", it doesn't matter at all. (At least I think so)
    it was a mere suggestion, if he wants to reuse this script in a bigger application someday

  4. #24
    Join Date
    Feb 2007
    Location
    Germany, Nuremburg
    Beans
    1,019
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Turning off Compiz for Games Script

    Quote Originally Posted by dexter.deepak View Post
    it was a mere suggestion, if he wants to reuse this script in a bigger application someday
    well, in that case, I suggest him to use python or C/C++, whereas he could implement the functions in the peding language and not nasty shellscript^^
    ... put your money where your mouth is ...
    stop sustaining Microsoft (and its pet named Apple)!
    Use the Thanks-button if you feel like!

  5. #25
    Join Date
    Oct 2007
    Location
    USA - Indiana
    Beans
    557
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SOLVED] Turning off Compiz for Games Script

    That's my next goal... learn python.... I'll try out that last code tonight.

  6. #26
    Join Date
    Oct 2007
    Location
    USA - Indiana
    Beans
    557
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Turning off Compiz for Games Script

    Quote Originally Posted by dexter.deepak View Post
    your "solution" script has a BIG flaw, when you issue :
    Code:
    killall gnome-terminal
    it will kill ALL the gnome-terminals you are currently running...and i dont think you would want this.
    thats why i used ppid, so that only the present terminal is closed.
    to make things more complex, i have to use the pppid now, ie, the pid of the command's (to find the pid) parent 's (this shell script) parent (the terminal).
    so here is the final code :
    Code:
    #!/bin/bash
    read -p "What game would you like to play?" GAME
    metacity --replace &
    $GAME
    compiz --replace &
    a=`ps -fp $$ |tail -1 | awk '{print $3}'`
    b=`ps -fp $a | tail -1| awk '{print $3}'`
    kill $b
    exit
    one more thing about your script...the exit status of your script is 1 - and this technically means that your script isnt yet perfect.
    i am also keen to know what purpose does 'sleep' solve for you ??
    Well.. I'm not sure that killing all of the gnome-terminals would be a problem in this case... I never have more than one terminal open anyways.... plus this script is being used when I am running a game... so I wouldn't be doing anything in the terminal anyways.

    But for the sake of learning... I am going to try it some other ways. Can you explain to me what $a and $b do exactly? I know it has something to do with finding the pppid... that's about all I know.

    What does an exit status of 1 mean?... and how do you know that it has that?

  7. #27
    Join Date
    Nov 2007
    Location
    india
    Beans
    485
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Turning off Compiz for Games Script

    Quote Originally Posted by anotherdisciple View Post
    Well.. I'm not sure that killing all of the gnome-terminals would be a problem in this case... I never have more than one terminal open anyways.... plus this script is being used when I am running a game... so I wouldn't be doing anything in the terminal anyways.
    ..and i thought you were doing this all for your friend
    Quote Originally Posted by anotherdisciple View Post
    What does an exit status of 1 mean?
    i am sorry for this..i actually tested your script in geany, and since there was no gnome-terminal there, i got an exit 1 status.
    Quote Originally Posted by anotherdisciple View Post
    Can you explain to me what $a and $b do exactly?
    $a gets the ppid of the command to calculate the ppid ...in our case the parent of the command (ps -fp...) is the shell-script itself.
    $b gets the parent of the shell-script..that is the terminal which invoked it.

  8. #28
    Join Date
    Oct 2007
    Location
    USA - Indiana
    Beans
    557
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SOLVED] Turning off Compiz for Games Script

    HAHA! Actually, I'm not much of a gamer... and my friend is not much of a terminal user... so it works both ways... I will probably use it since I spent all this time trying to figure it out, but it's mostly to make it easier on him... since he isn't very familiar with the command line.'

    About the $a and $b stuff... wow... I'm going to whip out my "Linux in a nutshell" and try to see how you came to that command... haha... it's a long and complicated one... I just want to know what it is doing to find that number... awk sounds familiar... not sure where I've used it before... hmmm... I'll get back to you about all this...

  9. #29
    Join Date
    Oct 2007
    Location
    USA - Indiana
    Beans
    557
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SOLVED] Turning off Compiz for Games Script

    ps= Report on active processes
    -fr= Forest, Running Processes
    $$= I have no clue (print all of the information?)
    tail -1= print only the last line
    awk = text based data
    print $3- print the third section of this data

    So, it says:

    Give me a full listing of all the running processes, filter it to only display the last line of those processes, and print only the data in the third section... which represents the id... but this is a bash script... and we want to close the terminal running that bash script... so we do it all over again... but sorting out what id is the parent of that particular bash script.

    Am I close?

  10. #30
    Join Date
    Oct 2007
    Location
    USA - Indiana
    Beans
    557
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SOLVED] Turning off Compiz for Games Script

    I tried this:

    Code:
    #!/bin/bash
    read -p "What game would you like to play?" GAME
    metacity --replace &
    sleep 3
    $GAME
    compiz --replace &
    sleep 3
    a=`ps -fp $$ |tail -1 | awk '{print $3}'`
    b=`ps -fp $a | tail -1| awk '{print $3}'`
    kill $b
    ... and yes, the sleep 3 after compiz --replace & is necessary. Without it... the terminal closes before it gets a chance to switch to compiz.... weird eh?

    The good news is that your script works... the bad news.... well.. it does the same thing as killall gnome-terminal! I opened a few gnome-terminals just to test it.... it killed all of them... not just the one I ran the script in. Any more ideas on how to sort it even further?

Page 3 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •