Note: If you see this text you use a browser which does not support usual Web-standards. Therefore the design of Media Art Net will not display correctly. Contents are nevertheless provided. For greatest possible comfort and full functionality you should use one of the recommended browsers.
Deutsch English

Matthias Weiß
«Matthias Weiß: Microanalysis of «Forkbomb»»

Matthias Weiß
Microanalysis of «Forkbomb»

Source Code
1 #!/usr/bin/perl -w
2 use strict;
3 die «Please do not run this script without reading the documentation» if not @ARGV;
4 my $strength = $ARGV[0] + 1;
5 while (not fork) {
6 exit unless --$strength;
7 print "0";
8 twist: while (fork) {
9 exit unless --$strength;
10 print "1";
11 }
12 }
13 goto 'twist' if --$strength;

In the first line path name, the symbols ‹#!,› which can be called ‹hash-bang› or ‹shebang,› instruct the shell, through which UNIX systems are accessed, to use Perl for executing the code. These lines of code are not executed by the interpreter—in this case Perl—but only instruct the operating system that the text and data in which the code itself resides is designated for the Perl interpreter. The characters that follow define the standard path to Perl. The ‹-w› at the end instructs the interpreter to produce error messages. As a rule, this is used when newly written programs are being tested. The command ‹strict› at the end tells the interpreter to generate error messages whenever the code is improperly written. The script itself is not something that can be started up with a double click on a symbol, like a text processor, as is normally the case for an icon paradigm with a graphical user interface. Instead, it is started via a command line where an integer value is input, that is then transferred to the program as the ‹strength› of the ‹bomb.› This specific value has to be entered. Otherwise, the following message appears: «Please do not run this script without reading the documentation» and the program breaks off. The ‹die› subroutine causes the system to carry this out. If the value of the argument, which is given on the command line and passed through the so-called special array ‹@ARGV,› is already zero, the program ends without generating messages. If a value in the form of a positive or negative integer is specified on the command line, the error messages are passed over, and the code which follows afterwards is executed.

In the fourth line, the variable ‹strength› is declared and defined. It has to be modified by ‹my› because the ‹strict› instruction forces the programmer to observe a rigid syntax. In this way, the system can immediately identify improper declarations. The value of ‹strength,› which corresponds to the special variable ($ARGV), is determined from the input value on the command line. After this, the value that the user has chosen is increased by 1 (line 4). Up to this point, the program has either broken off, after inviting the user to read the documentation, or has increased the strength of the bomb by 1. Now comes the actual part where the fork process is initiated. The ‹while› statement initiates a loop if the condition in the adjoining parenthesis (not fork) is not true. Despite this, the fork instruction triggers the first fork process.

If the system determines that ‹not fork = true,› then the program goes to the first loop. The program stops here ('exit,› line 6), if the variable ‹strength› has already become 0 (lines 9, 10) through a ‹decrement› process (indicated by ‹ -- ‹). In this case, a 0 is sent to the standard output (line 7) and the execution of the program continues from line 8.

Back in line 5, if the system determines that ‹(not fork)› is false, the program jumps to line 13 ('goto [...]'). At this point, the program is instructed to jump back to line 8. Another ‹fork› is started here. If the system comes back with ‹false,› the program again jumps back to line 13. If, during the process of ‹decrementing,› which is indicated by ‹--› , the variable ‹strength› is already 0 (lines 9, 10), and if the statement is ‹true,› the program stops again. Otherwise, the program produces the number 1 as an output, and continues on in line 13. The string continues to be executed until every process, by means of decrementing, goes to zero. This only occurs, however, if a positive value was input on the command line. If a negative value was entered, the program does not end. This is also the case for the program run if the first loop has ended and ‹strength› (line 6) is still not exactly 0. Along with the relationships of the conditions described in the program, and with the increasingly random dynamics that are produced by an output of 0 or 1, these processes are carried out identically in each offspring process (metaphorically speaking).