<commit_before>var spawn = require('child_process').spawn, 
    es    = require('event-stream');

module.exports = childrenOfPid

function childrenOfPid( pid, callback) {
  var headers = null;

  if('function' !== typeof callback) 
    throw new Error('childrenOfPid(pid, callback) expects callback')
  if('number' == typeof pid)
    pid = pid.toString()
  
  es.connect(
    spawn('ps', ['-A', '-o', 'ppid,pid,stat']).stdout,
    es.split(),
    es.map(function (line, cb) { //this could parse alot of unix command output
      var columns = line.trim().split(/\s+/)
      if(!headers)
        headers = columns
      else {
        var row = {}
        //for each header, 
        var h = headers.slice()
        while (h.length) {
          row[h.shift()] = h.length ? columns.shift() : columns.join(' ')
        }
        return cb(null, row)
      }
      return cb()
    }),
    es.writeArray(function (err, ps) {
      var parents = [pid], children = []
      ps.forEach(function (proc) {
        if(-1 != parents.indexOf(proc.PPID)) {
          parents.push(proc.PID)
          children.push(proc)
        }
      })
      callback(null, children)    
    })
  ).on('error', callback)
}
<commit_msg>add also the command name<commit_after>var spawn = require('child_process').spawn, 
    es    = require('event-stream');

module.exports = childrenOfPid

function childrenOfPid( pid, callback) {
  var headers = null;

  if('function' !== typeof callback) 
    throw new Error('childrenOfPid(pid, callback) expects callback')
  if('number' == typeof pid)
    pid = pid.toString()
  
  es.connect(
    spawn('ps', ['-A', '-o', 'ppid,pid,stat,comm']).stdout,
    es.split(),
    es.map(function (line, cb) { //this could parse alot of unix command output
      var columns = line.trim().split(/\s+/)
      if(!headers)
        headers = columns
      else {
        var row = {}
        //for each header, 
        var h = headers.slice()
        while (h.length) {
          row[h.shift()] = h.length ? columns.shift() : columns.join(' ')
        }
        return cb(null, row)
      }
      return cb()
    }),
    es.writeArray(function (err, ps) {
      var parents = [pid], children = []
      ps.forEach(function (proc) {
        if(-1 != parents.indexOf(proc.PPID)) {
          parents.push(proc.PID)
          children.push(proc)
        }
      })
      callback(null, children)    
    })
  ).on('error', callback)
}

{'fraction_non_alphanumeric': 0.1583710407239819, 'fraction_numerical': 0.0008227067050596463, 'mean_word_length': 2.229747675962815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3149588', 'n_tokens_mistral': 769, 'n_tokens_neox': 760, 'n_words': 180}