3.7. Background Execution of Commands

A major benefit of GNO/ME is multitasking. Multitasking is a means of running multiple applications at once (not literally but very close). On the Apple IIGS, GNO/ME accomplishes pre-emptive multitasking by switching among applications that are running in the background. Any GNO/ME utility can be run in the background. Applications running in the background generally run for the same period of time (GNO/ME switches between applications 20 times a second).

To background a shell utility, place the "&" character at the end of the command-line. The GNO shell displays a unique process ID and job number for each backgrounded command.

It is possible to use the background character "&" to separate commands as with the ";" character. Each command with a trailing "&" is executed in the background.

Up to 32 processes can executed concurrently under the GNO Kernel.

Warning: When you exit the GNO Shell all processes will be terminated including any you may have running in the background.

Below is a sample session with background tasks:


[5] script> ps
  ID STATE   TT MMID  UID TIME COMMAND
   1 ready   co 1002 0000 0:45 NullProcess
   2 ready   co 1007 0000 0:05 gsh
 138 running co 1006 0000 0:00 ps
[6] script> cmpl +p script.c keep=script > outputfile &
[1] + 141 Running cmpl +p script.c keep=script &
[7] script> ps
  ID STATE   TT MMID  UID TIME COMMAND
   1 ready   co 1002 0000 0:45 NullProcess
   2 ready   co 1007 0000 0:05 gsh
 141 waiting co 1006 0000 0:00 cmpl +p script.c keep=script
 142 ready   co 100B 0000 0:00 5/cc
 143 running co 100D 0000 0:00 ps
[8] script> cmpl +p script.asm keep=script1 > output2 & ps ; ls -s
[2] - 145 Running cmpl +p script.asm keep=script1 &
  ID STATE   TT MMID  UID TIME COMMAND
   1 ready   co 1002 0000 0:45 NullProcess
   2 ready   co 1007 0000 0:05 gsh
 141 waiting co 1006 0000 0:00 cmpl +p script.c keep=script
 144 ready   co 100E 0000 0:07 5/linker
 145 ready   co 100D 0000 0:00 cmpl +p script.asm keep=script1
 146 running co 100F 0000 0:00 ps
 147 ready   co 1011 0000 0:00 5/asm65816
   3 barf     1 outputfile  6 script.asm   1 script.root
   1 foobar  19 script      3 script.c    36 script.sym
   1 output2  6 script.a    6 script.mac   1 typescript
[9] script> cp script.asm script2 &
[3] 150 Running cp script.asm script2 &

[2] - Done cmpl +p script.asm keep=script1 &

[1] + Done cmpl +p script.c keep=script &

[3] - Done cp script.asm script2 &

[10] script> ps
  ID STATE   TT MMID  UID TIME COMMAND
   1 ready   co 1002 0000 0:45 NullProcess
   2 ready   co 1007 0000 0:05 gsh
 151 running co 1006 0000 0:00 ps

The first command line sends the ps command to the shell. ps lists the processes currently being executed by the GNO kernel. The processes named gsh and NullProcess are always present. For a complete description of the ps command, see Section 4.3.

When a command is executing in the background, keyboard input is not sent to it. However, output is still treated in the same way. If the command sends output to the standard output or standard error, the screen will become cluttered. Try this example:


[1]% ls -l&
[2]% ls -l

Both the output of commands #1 and #2 will be sent to the screen. After command #1 is entered and you begin typing command #2, you will see the output of the first "ls -l" command being sent to the screen while you enter command #2. Utilities which produce output should have their standard output and standard error redirected to a file when they are executed in the background. See Section 3.5.

Executing commands in the background hinders the performance of the Apple IIGS. This is not too noticeable when one or two commands are being executed but performance will degrade more noticably as more commands are started. The Apple IIGS was not designed as a multitasking computer so the performance of GNO/ME should be understandable. If you have an accelerator (such as the Transwarp GS or Zip GS) installed, performance of multiple tasks will be acceptable.