58ca4e68db
- Go backend API with full CRUD for all modules (CRM, Sales, Finance, HR, Legal, Marketing, Support, Purchase, Inventory, Projects, Automation, Analytics) - Rust analytics service with parallel report generation - C runtime with POSIX shared memory IPC - PostgreSQL schema with 30+ tables, full migrations - Redis cache, sessions, pub/sub - Kafka event streaming with Zookeeper - WebSocket hub for real-time updates - Automation engine with cron jobs, workflows, event triggers - JWT authentication, multi-tenant from start - Docker Compose with all services - Nginx reverse proxy with rate limiting - Integration tests passing - Feature gap analysis against Fortnox/Odoo/Visma Refs: BOC-001
54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
const spawn = require('child_process').spawn;
|
|
|
|
module.exports = { tree, pidsForTree, getStat };
|
|
|
|
function getStat() {
|
|
return new Promise((resolve) => {
|
|
const command = `ls /proc | grep -E '^[0-9]+$' | xargs -I{} cat /proc/{}/stat`;
|
|
const spawned = spawn('sh', ['-c', command], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
});
|
|
|
|
var res = '';
|
|
spawned.stdout.on('data', (data) => (res += data));
|
|
spawned.on('close', () => resolve(res));
|
|
});
|
|
}
|
|
|
|
function template(s) {
|
|
var stat = null;
|
|
// 'pid', 'comm', 'state', 'ppid', 'pgrp'
|
|
// %d (%s) %c %d %d
|
|
s.replace(
|
|
/(\d+) \((.*?)\)\s(.+?)\s(\d+)\s/g,
|
|
(all, PID, COMMAND, STAT, PPID) => {
|
|
stat = { PID, COMMAND, PPID, STAT };
|
|
}
|
|
);
|
|
|
|
return stat;
|
|
}
|
|
|
|
function tree(stats) {
|
|
const processes = stats.split('\n').map(template).filter(Boolean);
|
|
|
|
return processes;
|
|
}
|
|
|
|
function pidsForTree(tree, pid) {
|
|
if (typeof pid === 'number') {
|
|
pid = pid.toString();
|
|
}
|
|
const parents = [pid];
|
|
const pids = [];
|
|
|
|
tree.forEach((proc) => {
|
|
if (parents.indexOf(proc.PPID) !== -1) {
|
|
parents.push(proc.PID);
|
|
pids.push(proc);
|
|
}
|
|
});
|
|
|
|
return pids;
|
|
}
|