--  forkdemo3.adb
--    Shows how the return value from fork() allows a process to
--    determine whether is a child or a parent process.

with Ada.Text_IO, Interfaces.C;

with Fork, Get_Process_ID;

procedure Fork_Demo_3 is
   package int_Text_IO is new Ada.Text_IO.Integer_IO (Interfaces.C.int);
   use Ada.Text_IO, Interfaces.C, int_Text_IO;
   Child_Process_ID : int;
begin
   Put ("Before: My process ID is ");
   Put (Get_Process_ID, Width => 0);
   New_Line;

   Child_Process_ID := Fork;

   if Child_Process_ID < 0 then
      Put_Line (Standard_Error, "fork() failed");
   elsif Child_Process_ID = 0 then
      Put ("I am the child.  My process ID is ");
      Put (Get_Process_ID, Width => 0);
      New_Line;
   else
      Put ("I am the parent.  My child has process ID ");
      Put (Child_Process_ID, Width => 0);
      New_Line;
   end if;
end Fork_Demo_3;

