Wow, Collect2 sounds kinda hacky based on the linked documentation¹:
- There is user code that needs to run before main. With C/C++ allowing separate compilation, the compiler invocation that creates the entrypoint doesn't know about all of these static constructors.
- Therefore Collect2 pretends to be ld; when invoked, it tries to call the real ld and examines its output
- It creates a c file with a table containing any constructor symbols it finds, then compiles that
- Finally it links the program again, together with the new object file
I'm pretty sure the documentation actually lies though.
Yes, `collect2` exists, but with the existence of all the modern linker sections and scripts, it simply forwards everything to `ld` unchanged. There's no sneaky inspection, C code generation, or second linking pass.
Thanks for the clarification. I was questioning my sanity, because collect2 as described in the doc sounds not just hacky, but also like a waste of compile time.
FYI, you can also get a lot from the `time` command right now in your shell:
/usr/bin/time -v ls
Command being timed: "ls"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 100%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2304
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 117
Voluntary context switches: 1
Involuntary context switches: 0
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
this is a small personal nit complaint, but increasingly I see "Linux command-line" used to refer to things which have nothing to do with command-lines per se, which to me suggests some cli-fu with p|pes || other tricky \\&\\&& if-fi $(things).
Perhaps we need some better vocabulary to separate these ideas, but the world of unix includes "shell" ideas, and their interplay with cli, there's ascii text ttys, there's ansi tty control and TUIs, and what this article is about, traditional unix userspace process-space, system calls, C-libs, compilers vs interpreters got skipped, but C-vs-Rust, just all without the overhead of GUI frameworks which brings a bit more clarity to timings but they don't absolutely, to do timings could be better to write a program to launch all these things and make sure that program is "sticky" in unix space-time.
This is a good article, but because I like to search for things again later, just as a headline I wouldn't really call this exploring Linux command-line space or time
"Exploring a C program's memory use over time, on Linux" would be more accurate. Nothing in this article deals with our three spatial dimensions, the typical use of the word "space".
> you should consider explicating that space = memory, time = time.
That seems unnecessary. Even a layman knows that in the context of a computer, space != physical space. Most people think of disk space, but it can also refer to memory usage [0].
The meaning of the name was obvious to me after reading the first half of the first sentence of the article. I thought it was clever :)
FWIW, all these things date back to the ancient Usenet "RTFM" (where M = manual) which would undermine an expansion of "featured" in my view (since manuals are not "featured", like links in news aggregators). The other alternative Fs still work, though.
While I do like the idea, etc, and I know there are many examples of this, the actual name st is used by several other linux programs. Perhaps the author should consider calling it differently? For example (and I do have tape in most of my boxes, so st is installed on my main machine and my backup machine).
st SCSI Tape device
st simple terminal
Just wondering how others handle conflicts like this too...
Some terminals probably scroll sideways, but this `st` program seems to require running to completion. So, ^C does not give you any report at all.
While it does RSS not Proportional Set Size (PSS) { arguably parsing /proc/PID/smaps_rollup should be added } and does not integrate program launch with tracking or use netlink to track making kids, an alternative that might interest some is a scrolling terminal kind of log report out of the Nim https://github.com/c-blake/procs .
pd -pBHd1 -f "%N %R %< %> %J %a" $(pf firefox)
or launch the program with `prog &` and use the shell `$!` to specify the PID or add -D'R<>J' to get differential reports (or many other things). On the plus side, this can track many other things besides just memory & kids { like IO in the above example, assuming your Linux has /proc/PID/io support compiled in }.
You could always capture the output and feed it to some plotting program.
I've seen this design style before. I'm hoping there's an existing model to work from, e.g. how Tufte css spawned many individual layouts but instead inspired by a terminal.
- There is user code that needs to run before main. With C/C++ allowing separate compilation, the compiler invocation that creates the entrypoint doesn't know about all of these static constructors.
- Therefore Collect2 pretends to be ld; when invoked, it tries to call the real ld and examines its output
- It creates a c file with a table containing any constructor symbols it finds, then compiles that
- Finally it links the program again, together with the new object file
¹: https://gcc.gnu.org/onlinedocs/gccint/Collect2.html