Hacker News new | ask | show | jobs
by xthrowawayxx 1480 days ago
Sorrt, I can't tell if this is sarcasm.

Is there something I'm missing? Even the above examples look awful to me

1 comments

It's not sarcasm: I actually like PS because it builds on the concept of data pipelines, to turn them into something more object orientend.

The only thing similar in the Linux world is using sqlite as the target of pipe to do some data processing, like on a ps output, find the name of the process using the most RAM.

Structurally, the language seems both Perl inspired and something a bit like of an hybrid of LISP (for the object) and SQL (for how most structures are manipulated)

> I actually like PS because it builds on the concept of data pipelines, to turn them into something more object orientend.

It certainly is an interesting idea. I think the .Net dependency makes it more heavyweight than it might have otherwise been. I wonder if anyone at Microsoft has ever thought about porting it from C# to C++ (I suppose using COM/WinRT).

I think a big deficiency with pipes is they don’t come with any protocol for out-of-band content negotiation. Someone could add an IOCTL you could call on a write pipe (or Unix domain socket) to advertise supported MIME types, and blocks waiting for the other end to select one. The read end can call another IOCTL to get supported MIME types, and then a third to indicate its choice. If the read end doesn’t support this protocol, you could make it the first IOCTL is unblocked by the first read()/recvmsg() call on the read end, so this protocol still works even if the other end doesn’t support content negotiation. Utilities could default to producing text/plain, but generate application/json instead if the other end supports it.

In the FreeBSD world, we have libxo[0] which allows utilities to produce structured output.

To use your example, taking the output of ps and finding the process using the most RAM, you could do something like this:

  $ ps aux --libxo json|jq '."process-information"."process" | sort_by((.rss)|tonumber) | .[-1]'
  {
    "user": "root",
    "pid": "2372",
    "percent-cpu": "0.0",
    "percent-memory": "11.4",
    "virtual-size": "2149236",
    "rss": "1906584",
    "terminal-name": "- ",
    "state": "SC",
    "start-time": "21May22",
    "cpu-time": "1307:09.11",
    "command": "bhyve: postgresql (bhyve)"
  }
It's not pretty, but it does let you get structured data out of most of the base system utilities to make the slicing and dicing easier.

[0] https://www.freebsd.org/cgi/man.cgi?query=libxo&sektion=3