Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Common Lisp Process ID on Linux

I am wondering if there is a way to get Linux's PID (Process ID) from Common Lisp's REPL. That is, I would like to know the ID of the SBCL or Allegro process from the REPL of the process itself.

like image 235
MadPhysicist Avatar asked Dec 01 '22 10:12

MadPhysicist


2 Answers

There's nothing in the Common Lisp specification that implements this. Process IDs are too implementation-dependent.

In SBCL, the SB-POSIX package provides Lisp interfaces to most POSIX system calls, so you would use (sb-posix:getpid).

In Allegro CL, operating system interface functions are in the EXCL.OSI package, so you would use (excl.ose:getpid)

like image 178
Barmar Avatar answered Dec 04 '22 11:12

Barmar


There is a (basically) portable way to do this. CL provides for reading files and one can observe that the pid of the current process is in /proc/self/status (also /proc/self is a symlink to the process’ pid but I don’t think there’s a portable read link).

Specifically /proc/self/status is a text file and contains a line that looks like:

Pid: 439

So you could parse the file to extract that.

But then once you have the pid there isn’t much you can do with it without system calls or /proc weirdness

like image 39
Dan Robertson Avatar answered Dec 04 '22 13:12

Dan Robertson