Mercurial > hg > octave-terminal
changeset 4294:755f6509bb01
[project @ 2003-01-11 04:01:53 by jwe]
author | jwe |
---|---|
date | Sat, 11 Jan 2003 04:02:04 +0000 |
parents | 977f977fb2c3 |
children | fea24da316a2 |
files | liboctave/ChangeLog liboctave/oct-syscalls.cc liboctave/oct-syscalls.h src/ChangeLog src/sighandlers.cc src/syscalls.cc |
diffstat | 6 files changed, 265 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2003-01-10 John W. Eaton <jwe@bevo.che.wisc.edu> + + * oct-syscalls.cc (octave_syscalls::kill): New function. + * oct-syscalls.h: Provide decl. + + 2003-01-06 John W. Eaton <jwe@bevo.che.wisc.edu> * dMatrix.cc (Matrix::read): Set size and return immediately if
--- a/liboctave/oct-syscalls.cc +++ b/liboctave/oct-syscalls.cc @@ -321,6 +321,35 @@ return status; } +int +octave_syscalls::kill (pid_t pid, int sig) +{ + std::string msg; + return kill (pid, sig, msg); +} + +int +octave_syscalls::kill (pid_t pid, int sig, std::string& msg) +{ + msg = std::string (); + + int status = -1; + +#if defined (HAVE_KILL) + status = ::kill (pid, sig); + + if (status < 0) + { + using namespace std; + msg = ::strerror (errno); + } +#else + msg = NOT_SUPPORTED ("kill"); +#endif + + return status; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/liboctave/oct-syscalls.h +++ b/liboctave/oct-syscalls.h @@ -62,6 +62,9 @@ static pid_t waitpid (pid_t, int); static pid_t waitpid (pid_t, int, std::string&); + + static int kill (pid_t, int); + static int kill (pid_t, int, std::string&); }; #endif
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2003-01-10 John W. Eaton <jwe@bevo.che.wisc.edu> + + * sighandlers.cc (make_sig_struct): New function. + (symbols_of_sighandlers): Add DEFCONST for SIG struct. + + * syscalls.cc (Fkill): New function. + 2003-01-06 John W. Eaton <jwe@bevo.che.wisc.edu> * oct-stream.cc (get_size): If only one dimension is specified and
--- a/src/sighandlers.cc +++ b/src/sighandlers.cc @@ -42,6 +42,7 @@ #include "defun.h" #include "error.h" #include "load-save.h" +#include "oct-map.h" #include "pager.h" #include "pt-bp.h" #include "sighandlers.h" @@ -493,6 +494,154 @@ #endif } +static Octave_map +make_sig_struct (void) +{ + Octave_map m; + +#ifdef SIGABRT + m ["ABRT"](0) = SIGABRT; +#endif + +#ifdef SIGALRM + m ["ALRM"](0) = SIGALRM; +#endif + +#ifdef SIGBUS + m ["BUS"](0) = SIGBUS; +#endif + +#ifdef SIGCHLD + m ["CHLD"](0) = SIGCHLD; +#endif + +#ifdef SIGCLD + m ["CLD"](0) = SIGCLD; +#endif + +#ifdef SIGCONT + m ["CONT"](0) = SIGCONT; +#endif + +#ifdef SIGEMT + m ["EMT"](0) = SIGEMT; +#endif + +#ifdef SIGFPE + m ["FPE"](0) = SIGFPE; +#endif + +#ifdef SIGHUP + m ["HUP"](0) = SIGHUP; +#endif + +#ifdef SIGILL + m ["ILL"](0) = SIGILL; +#endif + +#ifdef SIGINFO + m ["INFO"](0) = SIGINFO; +#endif + +#ifdef SIGINT + m ["INT"](0) = SIGINT; +#endif + +#ifdef SIGIOT + m ["IOT"](0) = SIGIOT; +#endif + +#ifdef SIGLOST + m ["LOST"](0) = SIGLOST; +#endif + +#ifdef SIGPIPE + m ["PIPE"](0) = SIGPIPE; +#endif + +#ifdef SIGPOLL + m ["POLL"](0) = SIGPOLL; +#endif + +#ifdef SIGPROF + m ["PROF"](0) = SIGPROF; +#endif + +#ifdef SIGPWR + m ["PWR"](0) = SIGPWR; +#endif + +#ifdef SIGQUIT + m ["QUIT"](0) = SIGQUIT; +#endif + +#ifdef SIGSEGV + m ["SEGV"](0) = SIGSEGV; +#endif + +#ifdef SIGSTOP + m ["STOP"](0) = SIGSTOP; +#endif + +#ifdef SIGSYS + m ["SYS"](0) = SIGSYS; +#endif + +#ifdef SIGTERM + m ["TERM"](0) = SIGTERM; +#endif + +#ifdef SIGTRAP + m ["TRAP"](0) = SIGTRAP; +#endif + +#ifdef SIGTSTP + m ["TSTP"](0) = SIGTSTP; +#endif + +#ifdef SIGTTIN + m ["TTIN"](0) = SIGTTIN; +#endif + +#ifdef SIGTTOU + m ["TTOU"](0) = SIGTTOU; +#endif + +#ifdef SIGURG + m ["URG"](0) = SIGURG; +#endif + +#ifdef SIGUSR1 + m ["USR1"](0) = SIGUSR1; +#endif + +#ifdef SIGUSR2 + m ["USR2"](0) = SIGUSR2; +#endif + +#ifdef SIGVTALRM + m ["VTALRM"](0) = SIGVTALRM; +#endif + +#ifdef SIGIO + m ["IO"](0) = SIGIO; +#endif + +#ifdef SIGWINCH + m ["WINCH"](0) = SIGWINCH; +#endif + +#ifdef SIGXCPU + m ["XCPU"](0) = SIGXCPU; +#endif + +#ifdef SIGXFSZ + m ["XFSZ"](0) = SIGXFSZ; +#endif + + return m; +} + octave_child_list *octave_child_list::instance = 0; bool @@ -634,6 +783,12 @@ before reaching the debugging mode, a normal interrupt will occur.\n\ The default value is 0.\n\ @end defvr"); + + DEFCONST (SIG, make_sig_struct (), + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} SIG\n\ +Structure of Unix signal names and their defined values.\n\ +@end defvr"); } /*
--- a/src/syscalls.cc +++ b/src/syscalls.cc @@ -101,7 +101,7 @@ octave_value_list retval; retval(1) = std::string (); - retval(0) = -1.0; + retval(0) = -1; int nargin = args.length (); @@ -162,7 +162,7 @@ octave_value_list retval; retval(1) = std::string (); - retval(0) = -1.0; + retval(0) = -1; int nargin = args.length (); @@ -275,7 +275,7 @@ octave_value_list retval; retval(1) = std::string (); - retval(0) = -1.0; + retval(0) = -1; int nargin = args.length (); @@ -341,7 +341,7 @@ octave_value_list retval; retval(1) = std::string (); - retval(0) = -1.0; + retval(0) = -1; int nargin = args.length (); @@ -369,7 +369,7 @@ octave_value_list retval; retval(1) = std::string (); - retval(0) = -1.0; + retval(0) = -1; int nargin = args.length (); @@ -494,6 +494,58 @@ return retval; } +DEFUN (kill, args, , + "-*- textinfo -*-\n\ +@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} kill (@var{pid}, @var{sig})\n\ +Send signal @var{sig} to process @var{pid}.\n\ +\n\ +If @var{pid} is positive, then signal @var{sig} is sent to @var{pid}.\n\ +\n\ +If @var{pid} is 0, then signal @var{sig} is sent to every process\n\ +in the process group of the current process.\n\ +\n\ +If @var{pid} is -1, then signal @var{sig} is sent to every process\n\ +except process 1.\n\ +\n\ +If @var{pid} is less than -1, then signal @var{sig} is sent to every\n\ +process in the process group @var{-pid}.\n\ +\n\ +If @var{sig} is 0, then no signal is sent, but error checing is still\n\ +performed.\n\ +\n\ +Return 0 if sucessful, otherwise return -1.\n\ +@end deftypefn") +{ + octave_value_list retval; + + retval(1) = std::string (); + retval(0) = -1; + + if (args.length () == 2) + { + pid_t pid = args(0).int_value (true); + + if (! error_state) + { + int sig = args(1).int_value (true); + + if (! error_state) + { + std::string msg; + + int status = octave_syscalls::kill (pid, sig, msg); + + retval(1) = msg; + retval(0) = status; + } + } + } + else + print_usage ("kill"); + + return retval; +} + DEFUN (lstat, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ @@ -513,13 +565,13 @@ if (fs) { retval(2) = std::string (); - retval(1) = 0.0; + retval(1) = 0; retval(0) = mk_stat_map (fs); } else { retval(2) = fs.error (); - retval(1) = -1.0; + retval(1) = -1; retval(0) = Matrix (); } } @@ -545,7 +597,7 @@ octave_value_list retval; retval(1) = std::string (); - retval(0) = -1.0; + retval(0) = -1; int nargin = args.length (); @@ -599,7 +651,7 @@ octave_value_list retval; retval(2) = std::string (); - retval(1) = -1.0; + retval(1) = -1; retval(0) = Matrix (); int nargin = args.length (); @@ -738,13 +790,13 @@ if (fs) { retval(2) = std::string (); - retval(1) = 0.0; + retval(1) = 0; retval(0) = octave_value (mk_stat_map (fs)); } else { retval(2) = fs.error (); - retval(1) = -1.0; + retval(1) = -1; retval(0) = Matrix (); } } @@ -768,7 +820,7 @@ octave_value_list retval; retval(1) = std::string (); - retval(0) = -1.0; + retval(0) = -1; int nargin = args.length (); @@ -838,7 +890,7 @@ octave_value_list retval; retval(1) = std::string (); - retval(0) = -1.0; + retval(0) = -1; int nargin = args.length ();