Consider the following code : count.c .
Compile and run it to get something like this
$ gcc count.c -o count
$ ./count 2
./count 2
i=1 at 0 sec in process 12917
i=2 at 2 sec in process 12917
i=3 at 4 sec in process 12917
i=4 at 6 sec in process 12917
i=5 at 8 sec in process 12917
... typing control-C when we're tired of seeing it run.
We can also run it "in the background", meaning it detaches stdin from the terminal but continues on, and still outputs to the terminal ...
And we can start another.
Here are some things to try. (Check the man pages and/or google for options; there are many variations.)
jobs
shows the current running pipesps
shows the current processes%2
// where 2 is a job number ; reconnect that to the terminal%string
// same; looks for "string" as the start of a previous job commandcommand &
// run a command in the backgroundConcepts to understand : foreground, background, "attached to terminal", suspend, ...
jim@jupyter:procedures$ jobs
jim@jupyter:procedures$ ps
PID TTY TIME CMD
11044 pts/16 00:00:00 bash
13228 pts/16 00:00:00 ps
jim@jupyter:procedures$ ./count 10 &
[1] 13232
jim@jupyter:procedures$ i=1 at 0 sec in process 13232
jim@jupyter:procedures$ ./count 5 &
[2] 13235
jim@jupyter:procedures$ i=1 at 0 sec in process 13235
jim@jupyter:procedures$ i=2 at 10 sec in process 13232
i=2 at 5 sec in process 13235
i=3 at 10 sec in process 13235
i=3 at 20 sec in process 13232
jim@jupyter:procedures$ i=4 at 15 sec in process 13235
jim@jupyter:procedures$ jobs
[1]- Running ./count 10 &
[2]+ Running ./count 5 &
jim@jupyter:procedures$ i=5 at 20 sec in process 13235
jim@jupyter:procedures$ i=4 at 30 sec in process 13232
i=6 at 25 sec in process 13235
jim@jupyter:procedures$ i=7 at 30 sec in process 13235
jim@jupyter:procedures$ %1
./count 10
i=5 at 40 sec in process 13232
i=8 at 35 sec in process 13235
^Z
[1]+ Stopped ./count 10
jim@jupyter:procedures$
jim@jupyter:procedures$ jobs
[1]+ Stopped ./count 10
[2]- Running ./count 5 &
jim@jupyter:procedures$ i=9 at 40 sec in process 13235
jim@jupyter:procedures$ ps
PID TTY TIME CMD
11044 pts/16 00:00:00 bash
13232 pts/16 00:00:00 count
13235 pts/16 00:00:00 count
13256 pts/16 00:00:00 ps
jim@jupyter:procedures$ i=10 at 45 sec in process 13235
jim@jupyter:procedures$ ps t
PID TTY STAT TIME COMMAND
11044 pts/16 Ss 0:00 -bash
13232 pts/16 T 0:00 ./count 10
13235 pts/16 S 0:00 ./count 5
13257 pts/16 R+ 0:00 ps t
jim@jupyter:procedures$ i=11 at 50 sec in process 13235
jim@jupyter:procedures$ i=12 at 55 sec in process 13235
jim@jupyter:procedures$ i=13 at 60 sec in process 13235
jim@jupyter:procedures$ kill -9 1 i=14 at 65 sec in process 13235
3235
jim@jupyter:procedures$ jobs
[1]+ Stopped ./count 10
[2]- Killed ./count 5