Skip to content

Commit 2a11f1f

Browse files
committed
Add $&getpid primitive and use that to initialize $pid at startup.
This is actually an unrelated mailing list suggestion (see http://wryun.github.io/es-shell/mail-archive/msg00977.html) which just happens to work very well in the context of a %main hook.
1 parent 5dd39fe commit 2a11f1f

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

main.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
#include "es.h"
44

5-
/* initpid -- set $pid for this shell */
6-
static void initpid(void) {
7-
vardef("pid", NULL, mklist(mkstr(str("%d", getpid())), NULL));
8-
}
9-
105
/* main -- initialize, parse command arguments, and start running */
116
int main(int argc, char **argv) {
127
initgc();
@@ -18,7 +13,6 @@ int main(int argc, char **argv) {
1813

1914
runinitial();
2015

21-
initpid();
2216
initsignals();
2317
hidevariables();
2418
importenv(FALSE);

prim-etc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ PRIM(importenvfuncs) {
265265
return true;
266266
}
267267

268+
PRIM(getpid) {
269+
return mklist(mkstr(str("%d", getpid())), NULL);
270+
}
271+
268272
#if READLINE
269273
PRIM(resetterminal) {
270274
resetterminal = TRUE;
@@ -302,6 +306,7 @@ extern Dict *initprims_etc(Dict *primdict) {
302306
X(noreturn);
303307
X(setmaxevaldepth);
304308
X(importenvfuncs);
309+
X(getpid);
305310
#if READLINE
306311
X(resetterminal);
307312
#endif

runtime.es

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ let (
3636
)
3737
fn %main argv {
3838
fn-%main = ()
39+
pid = <=$&getpid
3940

4041
let (
4142
es = es

0 commit comments

Comments
 (0)