EggXpert

The official Newegg tech support community and Newegg tech support forums. Learn about PC building, case mods, computer repairs, and computer troubleshooting. Get help from knowledgable community members about computer hardware and computer software, laptops, notebooks, netbooks, consumer electronics & mp3 players, home networking, lcd TVs, home audio and more.
Welcome to eggXpert.com. Sign in | Join | Help
in Search
Advanced Search

Runbook: Linux.Start/Stop Applications

Last post 08-10-2009, 12:12 PM by ronaldprettyman. 5 replies.
Sort Posts: Previous Next
  •  05-15-2009, 11:07 PM 524874

    Runbook: Linux.Start/Stop Applications

    Last Modified: 6/11/09 @ 10:11 CST

    Since this is a simple one, I won't go through with the normal runbook layout.

     

    Starting Applications

    First you have to know who can run the application. There are two types of applications out there, ones that are designed for any normal user to use and those designed for only root to use. When you know who the application was meant for, then you have a general idea as to where it is. In a typical linux system, there are four places to look for all aplications.

    • /bin
    • /sbin
    • /usr/bin
    • /usr/sbin

    Any 'bin' folder will hold the normal bin(aries)--aka .exe files for you windows users. Any 'sbin' folder will hold all the superuser (root) bin files--ala sbin.

    So let's assume you want to start amarok 2, which is a music player (among other things) app. Fire up your trusty terminal screen. You should see a prompt similar to this:

    username@computername:~$

    A quick disect of this. ~ is short hand for your home directory (/home/username) and $ is short hand for 'normal user'. If you see # symbol, that's only when you are logged in as 'root'. Now typically you have the 'bin' type folders in your PATH environmental variable so you should be able to just type 'amarok' and it will launch the player. But let's say you don't have the bin folder sin your PATH. Well, first, what is PATH? Type this:

    echo $PATH

     An output similar to this should come back:

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

    That's a pretty basic PATH. This means that any executable files in those particular folders (each folder is separated by a colon) can be executed by just typing in the executable name and there is no need to type out the full path. Which leads us back to the assumption that '/usr/bin' isn't in your PATH (hint: amarok is found in /usr/bin folder), then you would type:

    /usr/bin/amarok [enter]

    As long as you have a GUI session running, amarok should start. 

    "But root, it hangs up my terminal screen and outputs random stuff"

    This is because you are running the program (aka 'job') in the foreground. When you see this, you can type 'Ctrl + Z' to stop the application. This will get you back to your $ prompt. Now type

    jobs [enter]

    Should say something like...

    [1]+  Stopped                 amarok

     This the [1] says it's the first job on your list and it's currently stopped. To resume it, we need to resume it either in the foreground (taking up your screen) or the background (hidden away to complete the job). Let's start it up in the background:

    bg 1

    This 'background' command is telling job number one to start up in the background. You can also run commands immediately in the background without having to CTRL Z it every time by adding a & at the end of the command:

    amarok & [enter]

    To learn more on jobs, I'd recommend this site.

     

    Stopping applications

    This isn't always obvious. Whenever in doubt, I use the equivilant of Window's Task Manager's 'End Task'. For those of you who aren't familiar with this technique, know that it's not the ideal way to close an application because you could be losing unsaved data. It's always recommend to NOT close applications this way. But sometimes you are forced to. It requires two steps.

    Say amarok is running and we want to close it, but for whatever reason it isn't responding and won't close. Type:

    ps aux | grep amarok [enter]

    This command uses ps ( process snapshot ) with a few parameters (aux) and pipe it ( | ) to the grep application which will search for the keyword 'amarok'. The output should be similar to this:

    username     25560  2.1  3.4 224516 71896 ?        Sl   00:55   0:04 /usr/bin/amarok
    username     25589  0.0  0.0   3336   804 pts/2    S+   00:58   0:00 grep amarok

    Since we are using 'grep', it will show up in this list but in reality the second line is no longer there after you see the ouput--which leaves us with '/usr/bin/amarok'. What you want to take from this output is the PID (process ID) which is the first number (25560 in this case). The PID is a unique, random number that's assigned to every running process. Since it's random, it won't be the same number every time so your PID for amarok won't be the same as mine in this example. Take that number and use it in the following command:

    kill 11 25560 [enter]

    This will 'end task' or 'kill' PID 25560--aka 'amarok' in this particular example. If it doesn't work, then it didn't like the 11 signal (SEGV)--which is a cleaner way to exit a program than actually killing it. Which leads us to signal 9, aka KILL. So replace 11 in the above command with 9 and that will definitely kill it.

    Again, you most likely won't see '25560' and will use something else. Now when you run the ps command you will see:

    username     26036  0.0  0.0   3336   792 pts/2    R+   01:02   0:00 grep amarok

    And look at that, the PID of the 'grep' command changed. Again, the grep command closes itself after completing, which it does shortly after it gives you the output.

    If you don't like ps command,  and want something more 'clean', you can use this command:

    pgrep -l amarok

    It will return all processes that contain 'amarok' and it's PID--excluding the 'grep' command unlike the ps command. 

     

    And there you have it. You now know how to start and stop applications.



    "Oh Gravity, Thou Art A Heartless b***h"

    -Sheldon

    Click to read my stories.
    Filed under: ,
  •  05-23-2009, 3:12 PM 527164 in reply to 524874

    Re: Runbook: Linux.Start/Stop Applications

    Thanks / for taking the time to put this together. I'm using more command lines everyday.

    Geeked 

     



  •  06-10-2009, 8:12 AM 533267 in reply to 527164

    Re: Runbook: Linux.Start/Stop Applications

    Thanks and I'm proud of you :-).

    I've updated it with a better approach.


    "Oh Gravity, Thou Art A Heartless b***h"

    -Sheldon

    Click to read my stories.
  •  06-11-2009, 5:38 AM 533495 in reply to 533267

    Re: Runbook: Linux.Start/Stop Applications

    root:

    Thanks and I'm proud of you :-).

    I've updated it with a better approach.

    Thanks to you Embarrassed

    This week I really had to use the command lines. In order to manually set up a ATI card to display on a TV.

    Geeked 



  •  06-14-2009, 8:38 AM 534627 in reply to 533495

    Re: Runbook: Linux.Start/Stop Applications

    Well-done Root

    IT is great to know some of the  command lines aha It had been a long time since the last time I watched your youtube Stick out tongue

    Keep up the great work 


    Only the Paranoid Survive
    T-T
    ~ ~ ~ ~
  •  08-10-2009, 12:12 PM 557093 in reply to 524874

    Re: Runbook: Linux.Start/Stop Applications

    pkill amarok
    killall amarok

    pkill -9 amarok ;-)

View as RSS news feed in XML

 Home   Forums   Chat   Blogs   Deals   Newsletter   About 

 FAQ   Terms of Use   Privacy Policy   Contact Us 

©2009 Newegg, Inc. All rights reserved.