module c.std_lib; extern (C): version (linux) // for Mandrake Linux 9.1 and ??? (RedHat 9.0??) { /* SMack 07.07.2003 - added declarations for some Mandrake Linux 9.1 dameon and signal calls. Remember to place "extern (C) { }" around the function that is passed to signal() since Linux system calls expect functions using the C calling convention. eg. test file dummy.d module dummy; import c.stdlib; import c.std_lib; extern (C) { void someSignalFunction(int signal) { switch (signal) { case SIGQUIT: printf("I've been signaled with: SIGQUIT: PID: %i\n", getpid()); break; default: printf("Hey not my signal! I've been signaled with: %i\n", signal); } } } void childDameonProcess() { int result; printf("\nChild Starting\n"); for(int i; i < 1000000000; i++) {} // Now raise a signal(SIGQUIT) for our signalhandler function result = raise(SIGQUIT); for(int i; i < 1000000000; i++) {} printf("Child Exiting!\n"); } int main() { int forkPID; printf("Parent Starting\n"); forkPID = fork(); if (forkPID > 0) printf("Child dameon started, Child PID:%i\n", forkPID); // Failed to spawn a new child process. if (forkPID < 0) printf("Dameon start failed!\n"); // Child has spwaned so continure loading the application code. if (forkPID == 0) { childDameonProcess(); // Child dameon code here return EXIT_SUCCESS; } printf("Parent Exiting\n"); return EXIT_SUCCESS; } */ // Add the following to dmd/src/phobos/c/std_lib.d /* ***** Extract from Mandrake Linux 9.1 signal man pages. ***** Standard Signals Linux supports the standard signals listed below. Several signal num- bers are architecture dependent, as indicated in the "Value" column. (Where three values are given, the first one is usually valid for alpha and sparc, the middle one for i386, ppc and sh, and the last one for mips. A - denotes that a signal is absent on the corresponding archi- tecture.) The entries in the "Action" column of the table specify the default action for the signal, as follows: Term Default action is to terminate the process. Ign Default action is to ignore the signal. Core Default action is to terminate the process and dump core. Stop Default action is to stop the process. */ // Signal Value Action Comment // ------------------------------------------------------------------------- const int SIGHUP = 1; // Term Hangup detected on controlling terminal or death of controlling process const int SIGINT = 2; // Term Interrupt from keyboard const int SIGQUIT = 3; // Core Quit from keyboard const int SIGILL = 4; // Core Illegal Instruction const int SIGABRT = 6; // Core Abort signal from abort(3) const int SIGFPE = 8; // Core Floating point exception const int SIGKILL = 9; // Term Kill signal const int SIGSEGV = 11; // Core Invalid memory reference const int SIGPIPE = 13; // Term Broken pipe: write to pipe with no readers const int SIGALRM = 14; // Term Timer signal from alarm(2) const int SIGTERM = 15; // Term Termination signal const int SIGUSR1 = 10; //30,10,16 //Term User-defined signal 1 const int SIGUSR2 = 12; //31,12,17 //Term User-defined signal 2 const int SIGCHLD = 17; //20,17,18 //Ign Child stopped or terminated const int SIGCONT = 18; //19,18,25 // Continue if stopped const int SIGSTOP = 19; //17,19,23 //Stop Stop process const int SIGTSTP = 20; //18,20,24 //Stop Stop typed at tty const int SIGTTIN = 21; //21,21,26 //Stop tty input for background process const int SIGTTOU = 22; //22,22,27 //Stop tty output for background process //The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored. //#include //#include //pid_t fork(void) typedef int pid_t; pid_t fork(); //#include //#include pid_t getpid(); pid_t getppid(); //#include //typedef void (*sighandler_t)(int); //sighandler_t signal(int signum, sighandler_t handler); typedef void (* sighandler_t)(int); sighandler_t signal(int signum, sighandler_t handler); //#include int raise(int sig); }