---Start a process---
Different from Windows an executable don't need a special file extension (like .exe) on Linux/Unix, so the extension can be anything or even no extension at all. But it is a good practice to give Bash scripts a .sh extension for example, so executables can be easier identified, especially on a multi-user system and/or if colors are not enabled in the terminal (executables are usually displayed in a yellow-ish color).
So, how to start a process? Simple, you just have to enter the name of the executable, if you are not in the same irectory as the executable you have to use the full or relative path like:
Code: Select all
/usr/local/myprocess
Code: Select all
./myprocess
But of course there is a way to start executables just by entering the name, for this the executable must be located inside one of the paths where the shell interpreter looks for them.
The paths are stored in the $PATH variable:
Code: Select all
serv:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
Code: Select all
myprocess
First, let's start your process again, asuming it's in $PATH:
Code: Select all
myprocess
So, let's start the process again, but this time as background process:
Code: Select all
myprocess &
Hm, wait, when I close the terminal the process ends too....
Ok, also no problem, let's start the process again as background process that will keep running even when you log out:
Code: Select all
nohup myprocess &
Another problem that might appear is that the process prints its output on the screen, if the output is kinda useful and you want to log it for later checks you can easily write it to a file:
Code: Select all
myprocess > /mylogfile &
Code: Select all
myprocess > /dev/null &
---Stop a process---
Well, how to stop a process kinda depends on you, I am not talking about violently kill a process now, I mean how to stop it regularly. The best is of course when you have implemented this option in your code already or you use an external start/stop script (this applies to permanent processes like servers for example). But a process of course also simply end by itself when it is done with its job (like a backup script for example).
---To stop a process that "hangs"---
If there is an error in the code for example it can happen that the process doesn't end like it should, this can lead to various problems from a high load on a server system to freezing the complete desktop on a desktop system.
What you NEVER should do is to press the "reset" button, this is really only the LAST option because it can lead to a loss of the data that was processed at that moment or it can even corrupt a whole database.
Let's start with the most simple case when you run a process in the shell and it hangs so the terminal is blocked, pressing CTRL+C should end the process.
Another way is the "kill" command, if the terminal is not blocked and/or you can open a 2nd one you can stop the process with:
Code: Select all
kill <PID>
There are different ways, you can use the "top" command or "ps -A", if you know the name of the process you can also use the "pdiof" command:
Code: Select all
pidof myprocess
Code: Select all
kill -9 725
Now let's imagine you started your process on your desktop system and "uh-oh...desktop frozen!"...still no need to press "reset", even if your mouse and keyboard seem to have no effect.
By pressing CTRL+Alt+F1 you have a good chance to switch into textmode where you can end the process that caused the hang with the methods mentioned above.
---Getting info about processes---
As mentioned about (process PID) there are different ways to get informations about processes, the most basic one is:
Code: Select all
ps -A
If you want to have more detailed info "ps aux" is a very useful command, it display information like the process owner, PID, CPU and RAM usage, etc., a very valuable info is the actual command that started the process.
If you want to have info in realtime the "top" command is very useful, it also displays CPU and RAM usage, so it is very good to monitor the system if you suspect a process to be a resource hog.
Both ps and top have numberous options, so I recommend to check the manual pages.
---Be nice!---
Um, what? No joke, you can tell a process to be nice! Ok, actually you can give a process a priority, which means a processe with higher priority gets time (better said CPU runtime) to finish first before the process with lower priority is allowed to use the resources.
And the command for this is "nice". the highest priority is -20, the lowest priority is 19.
So let's start out process with the highest priority:
Code: Select all
nice -20 myprocess
The "nice" command is only used to start a new process, if the process is already running and you want to give it a different priority you will have to use the "renice" command.
So let's give our already running process (with the PID 725) a different priority (-5) because -20 was a little too much:
Code: Select all
renice -5 725
Alright, that's all for now, I hope you find this little tut useful...
![Smile :)](./images/smilies/icon_smile.gif)