Browse Source

Add __pid internal variable

Serj Kalichev 10 years ago
parent
commit
770bc1fcc8
1 changed files with 8 additions and 0 deletions
  1. 8 0
      clish/shell/shell_var.c

+ 8 - 0
clish/shell/shell_var.c

@@ -6,6 +6,8 @@
 #include <assert.h>
 #include <string.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include "lub/string.h"
 #include "private.h"
@@ -111,6 +113,12 @@ static char *find_context_var(const char *name, clish_context_t *this)
 		else
 			result = strdup("0");
 
+	} else if (!lub_string_nocasecmp(name, "_pid")) {
+		char tmp[10];
+		snprintf(tmp, sizeof(tmp), "%u", getpid());
+		tmp[sizeof(tmp) - 1] = '\0';
+		result = strdup(tmp);
+
 	} else if (lub_string_nocasestr(name, "_prefix") == name) {
 		int idx = 0;
 		int pnum = 0;