wxMaxima
Loading...
Searching...
No Matches
Data Structures | Functions
ProcessTree.h File Reference

Declares DescendantPids(), which finds every process started below a given one. More...

#include <vector>
Include dependency graph for ProcessTree.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ProcessEntry
 One process of a process list: its own id and the id of its parent. More...
 

Functions

std::vector< long > DescendantPids (long root, const std::vector< ProcessEntry > &processes)
 Returns root and all its descendants in processes, root first.
 

Detailed Description

Declares DescendantPids(), which finds every process started below a given one.

Function Documentation

◆ DescendantPids()

std::vector< long > DescendantPids ( long  root,
const std::vector< ProcessEntry > &  processes 
)

Returns root and all its descendants in processes, root first.

On MS Windows wxMaxima does not start Lisp directly: it starts maxima.bat (or whatever the user configured as Maxima), which in turn starts the Lisp. To interrupt a computation we need to find the named shared-memory segment the Lisp created, and that name contains the Lisp's own process id – which is only known if Maxima's first prompt told us about it. Walking the process tree below the process we started gives us every candidate instead.

The walk is breadth-first, so the closest descendants come first. It is deliberately robust against what a real Windows process snapshot can contain: process ids are reused, so a parent id may name a process that died and whose id was handed to an unrelated process since. That can make an unrelated process look like a child, or even create a cycle; every pid is therefore reported at most once. A false positive is harmless for the caller, which only looks for a shared-memory segment of that name.

Pure and portable, so it can be tested on every platform.