summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-07-30 18:56:17 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-07-30 18:56:17 -0700
commitb1acf6517d808242c6c46b09250925ff20861cc4 (patch)
tree67175dc4c16f8ee95b79043e2d35ce95879ba176
parentff4d78c938128cd0572f6469425005d9019a7f38 (diff)
downloadtxr-b1acf6517d808242c6c46b09250925ff20861cc4.tar.gz
txr-b1acf6517d808242c6c46b09250925ff20861cc4.tar.bz2
txr-b1acf6517d808242c6c46b09250925ff20861cc4.zip
* 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.
-rw-r--r--ChangeLog10
-rw-r--r--eval.c16
-rw-r--r--signal.c7
-rw-r--r--txr.129
4 files changed, 62 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index c5d9a706..803685df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2014-07-30 Kaz Kylheku <kaz@kylheku.com>
+ * 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 <kaz@kylheku.com>
+
* parser.l: Allow unquotes and splices in QSPECIAL and BRACED states.
* parser.y (quasi_item): Support splices as items.
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 <process-id> [<signal>])
+
+.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 <signal> 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