~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to docs/olinuxex/ex71.pp

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
program TestC{lone};
2
 
 
3
 
uses
4
 
  oldlinux, Errors, crt;
5
 
 
6
 
const
7
 
  Ready : Boolean = false;
8
 
  aChar : Char    = 'a';
9
 
 
10
 
function CloneProc( Arg: Pointer ): LongInt; Cdecl;
11
 
begin
12
 
  WriteLn('Hello from the clone ',PChar(Arg));
13
 
  repeat
14
 
    Write(aChar);
15
 
    Select(0,Nil,Nil,Nil,Nil);
16
 
  until Ready;
17
 
  WriteLn( 'Clone finished.');
18
 
  CloneProc := 1;
19
 
end;
20
 
 
21
 
var
22
 
  PID : LongInt;
23
 
 
24
 
procedure MainProc;
25
 
begin
26
 
  WriteLn('cloned process PID: ', PID );
27
 
  WriteLn('Press <ESC> to kill ... ' );
28
 
  repeat
29
 
    Write('.');
30
 
    Select(0,Nil,Nil,Nil,Nil);
31
 
    if KeyPressed then
32
 
      case ReadKey of
33
 
        #27: Ready := true;
34
 
        'a': aChar := 'A';
35
 
        'A': aChar := 'a';
36
 
        'b': aChar := 'b';
37
 
        'B': aChar := 'B';
38
 
      end;
39
 
  until Ready;
40
 
  WriteLn('Ready.');
41
 
end;
42
 
 
43
 
const
44
 
  StackSze = 16384;
45
 
  theFlags = CLONE_VM+CLONE_FS+CLONE_FILES+CLONE_SIGHAND;
46
 
  aMsg     : PChar = 'Oops !';
47
 
 
48
 
var
49
 
  theStack : Pointer;
50
 
  ExitStat : LongInt;
51
 
 
52
 
begin
53
 
  GetMem(theStack,StackSze);
54
 
  PID := Clone(@CloneProc,
55
 
               Pointer( LongInt(theStack)+StackSze),
56
 
               theFlags,
57
 
               aMsg);
58
 
  if PID < 0 then
59
 
    WriteLn('Error : ', LinuxError, ' when cloning.')
60
 
  else
61
 
    begin
62
 
    MainProc;
63
 
    case WaitPID(0,@ExitStat,Wait_Untraced or wait_clone) of
64
 
      -1: WriteLn('error:',LinuxError,'; ',StrError(LinuxError));
65
 
       0: WriteLn('error:',LinuxError,'; ',StrError(LinuxError));
66
 
    else
67
 
      WriteLn('Clone exited with: ',ExitStat shr 8);
68
 
    end;
69
 
    end;
70
 
  FreeMem( theStack, StackSze );
71
 
end.
 
 
b'\\ No newline at end of file'