Jump to content
Excelsior Forums
Sign in to follow this  
qnr

making system calls ... signal, for example

Recommended Posts

I'm really starting to pull my hair out here.  how do I call signal?

I can't get sigaction or signal to work, no matter what I do.

If I make sigChildHandler a funtion, and use

RETURN SIG_DFL;

and call it with:

sigChildHandler(SIGCHLD);

it compiles ok, but doesn't work (and it shouldn't, as far as I can see).  If I do it like the regular C call, all I get are compilation errors like:

* [signal01.mod 30.19 E152]
* incompatible calling conventions:
    "signal.sighandler_t"
    "PROCEDURE [Modula] (INT32)"
  signal(SIGCHLD, $sigChildHandler);

MODULE signal01;

FROM STextIO IMPORT WriteString, WriteLn;
FROM signal IMPORT signal, sighandler_t, sigset_t, SIGCHLD, SIG_DFL;
FROM types IMPORT pid_t;
FROM unistd IMPORT fork, sleep;
FROM wait IMPORT waitpid, WNOHANG;

IMPORT SYSTEM;

VAR
  func: sighandler_t;
  pid : pid_t;

PROCEDURE sigChildHandler( p : pid_t ); (*: sighandler_t; *)
VAR
  statloc : INTEGER;
BEGIN
  WHILE (waitpid( -1, statloc, WNOHANG ) > 0) DO
  END;
  WriteString("Child has ended.");
  WriteLn;
(*  RETURN SIG_DFL; *)
END sigChildHandler;



BEGIN
(* func := sigChildHandler(SIGCHLD); *)
  signal(SIGCHLD, sigChildHandler);

  pid := fork();
  IF pid = 0 THEN
    WriteString("La de dah.. starting child process, and pausing 5 seconds.");
    WriteLn;
    sleep(5);
  END;

  LOOP
    
  END;

END signal01.

Share this post


Link to post
Share on other sites

OK, I brushed up on my PROCEDURE types info, and I have signal working as expected, using ["C"]

Still don't have sigaction going though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×