4 ms·
> With text you just read and parse, while with objects you need to know the object type, its fields parsing is actually a huge pain in general. a lot of unix
by philsnow 10y ago
> With text you just read and parse, while with objects you need to know the object type, its fields
parsing is actually a huge pain in general. a lot of unixy tools produce different output when their stdout is not a terminal to be more pipeline-friendly. That output is generally easier to parse (often tab-separated or so), but you still need to know the same things about the output (the "type" could be whether it came from `ps` or from `ls`, and the fields are just in some static order that was usually chosen decades ago, and if it's extensible it's cumbersome).
If `ps`, `ls`, etc produced typed output, I would be sooo happy.
When I worked at google I thought about what it would be like to have a unix userland where all the parts communicate with protobufs instead of raw text. There are some problems (like portability of message definitions, which was a solved problem within google, but which is harder when you have multiple parties/entities/companies contributing message definitions).
edit: accidentally a word
- Klathmon 10y agoI wrote a bash script to sort processes by age on an old redhat 4 machine. What sounded like a very simple thing, quickly ended up being a complete nightmare of bash, python, and an unholy bunch of linux commands. It was ugly, and a terrible way of doing it, but we got it working. It would have been amazing if i could pipe PS into something that could sort by the dates on the 4th column, and return the last column in the sorted order.
- PeCaN 10y agoYou could probably hack something together with awk, but this sort of thing is exactly why I like powershell a lot.
- Klathmon 10y agoYeah i ended up using awk, some python for the date parsing and sorting, back to bash for grep and another thing i can't remember, then into the program that actually needed the data. It was a mess, and I remember thinking it would be such a simple thing that was so much more complicated than i thought it would be.
- mining 10y agoIt's entirely possible this is a recent development, but "ps -o cmd --sort etime" seems to do what you're asking for.
- Klathmon 10y agosadly that wasn't available, and researching an easier way to do it without that was met with pages and pages of people saying to do that...
- dangerlibrary 10y agoThere's literally an example in 'man ps' that does exactly this. It's right there in the output formatting section. ps kstart_time -ef
- daveloyall 10y agoPretty sure the section in the `ps` man page called OBSOLETE SORT KEYS indicates that even the `ps` on very old redhat machines could do this out of box... see the field `start_time`. Failing that, consider the `etimes` field (seconds since process was started) used in conjunction with the -o feature (control output format) so you can put `etimes` up front then simple pipe the output to `sort`. Those things being said, the situation you describe is indeed hairy. `ps` output was designed for human consumption, that's why the process age field format varies (1w vs 10:15) and that's presumably why you wanted to bring python into the mix! ...You might have had an easier time looking in /proc... Indeed, this looks promising: cat /proc/[0-9]*/stat|sort -n|less -S EDIT: hm, I don't know how old /proc is! EDIT #2: But try doing ANY of this on an ancient Windows machine! The "peer" of your old Redhat machine would be what, a Win2k3 machine, or a Win2k? How old is PowerShell? :)
- Klathmon 10y agoHonestly it was a quick and dirty one-time project, and I just needed to cobble something together. I was more just commenting on the fact that with a "strongly-typed" shell some of this stuff becomes much easier without every single tool needing to add all these options. It gets much more "Unix Philosophy" when every command doesn't need it's own sorting logic, and doesn't need it's own date display logic, and doesn't need it's own way of displaying it to the user. It can output an object, which can be piped into another program to use what it needs which can be piped to something else to do some sorting which can pipe it out to another to display it in a nice table.
- daveloyall 10y agoI hear you. I myself was impressed by some things PowerShell can do easily. But let's not throw out the baby with the bathwater... The unix shell ecosystem is powerful magic. There are LOTS of things that can be done there with great ease. Not to mention--and I understand full well that this stance is falling out of fashion--MICROSOFT ... KILLED... my PAPPY! :|
- jve 10y agoPowerShell was released after Win2k3, however you could install it on Win2k3/XP, even PowerShell 2 afterwards: https://support.microsoft.com/en-us/kb/968929 https://support.microsoft.com/en-us/kb/968929