From b1acf6517d808242c6c46b09250925ff20861cc4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 30 Jul 2014 18:56:17 -0700 Subject: * eval.c (getpid_wrap, getppid_wrap): New static functions. (eval_init): Registered getpid and getppid intrinsics. * signal.c (kill_wrap): New static function. (sig-init): Registered kill intrinsic function. * txr.1: Documented getpid, gettpid and kill. --- ChangeLog | 10 ++++++++++ eval.c | 16 ++++++++++++++++ signal.c | 7 +++++++ txr.1 | 29 +++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/ChangeLog b/ChangeLog index c5d9a706..803685df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2014-07-30 Kaz Kylheku + + * eval.c (getpid_wrap, getppid_wrap): New static functions. + (eval_init): Registered getpid and getppid intrinsics. + + * signal.c (kill_wrap): New static function. + (sig-init): Registered kill intrinsic function. + + * txr.1: Documented getpid, gettpid and kill. + 2014-07-30 Kaz Kylheku * parser.l: Allow unquotes and splices in QSPECIAL and BRACED states. diff --git a/eval.c b/eval.c index 9119b0f4..56005153 100644 --- a/eval.c +++ b/eval.c @@ -3294,6 +3294,18 @@ static val usleep_wrap(val usec) return retval; } +#if HAVE_UNISTD_H +static val getpid_wrap(void) +{ + return num(getpid()); +} + +static val getppid_wrap(void) +{ + return num(getppid()); +} +#endif + static val env_hash(void) { val env_strings = env(); @@ -3997,6 +4009,10 @@ void eval_init(void) reg_fun(intern(lit("errno"), user_package), func_n1o(errno_wrap, 0)); reg_fun(intern(lit("exit"), user_package), func_n1(exit_wrap)); reg_fun(intern(lit("usleep"), user_package), func_n1(usleep_wrap)); +#if HAVE_UNISTD_H + reg_fun(intern(lit("getpid"), user_package), func_n0(getpid_wrap)); + reg_fun(intern(lit("getppid"), user_package), func_n0(getppid_wrap)); +#endif reg_fun(intern(lit("env"), user_package), func_n0(env)); reg_fun(intern(lit("env-hash"), user_package), func_n0(env_hash)); diff --git a/signal.c b/signal.c index a4139b1b..033a9ec8 100644 --- a/signal.c +++ b/signal.c @@ -97,6 +97,12 @@ static void sig_handler(int sig) } } +static val kill_wrap(val pid, val sig) +{ + cnum p = c_num(pid), s = c_num(default_arg(sig, num_fast(SIGTERM))); + return num(kill(p, s)); +} + void sig_init(void) { int i; @@ -160,6 +166,7 @@ void sig_init(void) reg_fun(intern(lit("set-sig-handler"), user_package), func_n2(set_sig_handler)); reg_fun(intern(lit("get-sig-handler"), user_package), func_n1(get_sig_handler)); reg_fun(intern(lit("sig-check"), user_package), func_n0(sig_check)); + reg_fun(intern(lit("kill"), user_package), func_n2o(kill_wrap, 1)); } #if HAVE_SIGALTSTACK diff --git a/txr.1 b/txr.1 index 53826f82..176d665c 100644 --- a/txr.1 +++ b/txr.1 @@ -14331,6 +14331,20 @@ This function retrieves the current working directory. If the underlying getcwd system call fails with an errno other than ERANGE, an exception will be thrown. +.SS Functions getpid and getppid + +.TP +Syntax: + + (getpid) + (getppid) + +.TP +Description: + +These functions retrieve the current proces ID and the parent process ID +respectively. They are wrappers for the POSIX functions getpid and getppid. + .SS Function daemon .TP @@ -14579,6 +14593,21 @@ Calls to the sig-check function may be inserted into CPU-intensive code that has no opportunity to be interrupted by signals, because it doesn't invoke any I/O functions. +.SS The kill function + +.TP +Syntax: + + (kill []) + +.TP +Description: + +The kill function is used for sending a signal to a process group or process. +It is a wrapper for the POSIX kill function. + +If the argument is omitted, it defaults to the same value as sig-term. + .SH UNIX SYSLOG On platforms where a Unix-like syslog API is available, TXR exports this -- cgit v1.2.3