gcc
or cc
: C Compiler.
Usage : To compile a C program,
gcc -o prog_name file.c files_*.c -lm
g77
or f77
: Fortran 77 Compiler.
Usage : To compile a Fortran program
g77 -o prog_name file.f files_*.f
prog_nameTo run the compiled program in the background
prog_name &
<ctrl>c
: To interrupt a running program
Usage : Press the Ctrl
key and the c
key together if you want to stop the running program
<ctrl>z
: To suspend a running program
Usage : Press the Ctrl
key and the z
key together if you to want suspend the running program
bg
: To run the suspended job in the background, that is, the
program is running but you get your command prompt back
fg
: To run the suspended job in the foreground, that is, the
program is running and you don't get your command prompt back. Also to bring
a process running in the background to the foreground.
jobs
: To list your jobs running in the background
ps
: To list all processes
running in the background and foreground.
Usage:
To list processes started in that shell only,
ps
To list all your processes
ps -u
kill
: To kill a job or a process
Usage: First do
jobsto get the job number or do
ps -uto get the process number. Then
kill %3to kill the job number 3, for instance, or
kill process_numberto kill a process with
process_number
.
To overkill,
kill -9 %job_number or kill -9 process_number
Suppose you have written a C program file called solve_everything.c
.
To compile,
HAL9000> cc solve_everything.cHere
cc
is the ``C Compiler".
In Linux this is just linked to the `gnu cc' or gcc
. So might as well
use gcc
in place of cc
. Your choice.
If solve_everything.c
is a simple program that doesn't require any library
files, this will produce an executable file called a.out
.
You might
want to check by typing ls
to see if it is really there. If it is
there, just type
HAL9000> a.outand all the world's problem will be solved.
However, C programs are usually more complex and you don't want to use
a.out
for the name of every program you write.
Also, you are going to need the library functions.
The most important of
all libraries, at least for me, is the math library. If you use any
math in your program, that is, if there is a line in your program that says,
#include <math.h>you need this library. Also, large programs usually have many separate
.c
files.
So if you want to call your program solve_this
, and if you need the
math library, do
HAL9000> gcc -o solve_this solve_everything.c others_*.c -lmThe
-o
here means ``output" and -lm
means ``link math library".
The name of the library file used in this case
is libm.so
or libm.a
.
If the library you need
is called libWhatever.so
or libWhatever.a
, then
use -lWhatever
.
Now you can run this program by typing
HAL9000> solve_thisDoing so makes you lose the command prompt while the program is running. To get the prompt back with the job running in the background, do
HAL9000> solve_this &
For Fortran programs, use
HAL9000> g77 -o solve_this solve_everything.f other_files.fYou can also use
f77
in place of g77
, but that's just another
name for g77
anyway.
To run it
HAL9000> solve_this or HAL9000> solve_this &as before. Note that you don't need to specify a library for math functions in Fortran.
If something goes wrong and you want to stop the program running in the
foreground,
the interrupt signal in Unix is <ctrl>c
which kills the program, or <ctrl>z
which
merely suspends the program.
There are two ways to resume the suspended program.
Sometimes you want to run the program in the background. That is, you want
the program to resume
but also want the command prompt back. No problem. Just say
HAL9000> bgIf there are many suspended runs, do first
HAL9000> jobsto get the job number and do
HALL9000> bg %3to restart, for instance, the job #3.
On the other hand, sometimes you want the program to resume in the foreground. That is, you don't want your command prompt back. In that case, just say
HAL9000> fg or HAL9000> fg %3This job can be interrupted by
<ctrl>c
and <ctrl>z
again.
Sometimes, your program may completely freeze a window while running in the foreground. In that case, you need to know the process number to kill it. To list processes started in that shell only (in practice, this means processes started in that xterm),
ps
To list all your processes
ps -u
If your job can take longer than 30 minutes, you should put it
in the batch que: The format is as follows.
To run a long job on hal9000
qsub -M -tjob_name hall9000 batch_scriptFor details, do
info qsubIf you run a program which does not give you a command prompt, it will be shut off after 30 minutes unless it is submitted using
qsub
.
You can also check the status of machines and jobs by doing
qstat or qstat machine_name
To kill a process or a background job, first do
jobsto get the job number or do
ps -uto get the process number. Then
kill %3to kill the job number 3, for instance, or
kill process_numberto kill a process associated with
process_number
.
Sometimes the process cannot be killed by simple kill
. Then you have
force it. To overkill,
kill -9 %job_number or kill -9 process_number