ex57.pp 768 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. Program example57;
  2. { Program to demonstrate the SigAction function.}
  3. {
  4. do a kill -USR1 pid from another terminal to see what happens.
  5. replace pid with the real pid of this program.
  6. You can get this pid by running 'ps'.
  7. }
  8. uses BaseUnix;
  9. Var
  10. oa,na : PSigActionRec;
  11. Procedure DoSig(sig : cint);cdecl;
  12. begin
  13. writeln('Receiving signal: ',sig);
  14. end;
  15. begin
  16. new(na);
  17. new(oa);
  18. na^.sa_Handler:=TSigaction(@DoSig);
  19. fillchar(na^.Sa_Mask,sizeof(na^.sa_mask),#0);
  20. na^.Sa_Flags:=0;
  21. {$ifdef Linux} // Linux specific
  22. na^.Sa_Restorer:=Nil;
  23. {$endif}
  24. if fpSigAction(SigUsr1,na,oa)<>0 then
  25. begin
  26. writeln('Error: ',fpgeterrno,'.');
  27. halt(1);
  28. end;
  29. Writeln ('Send USR1 signal or press <ENTER> to exit');
  30. readln;
  31. end.