You can't get kernel-specific things like strace, but they do have just about everything else. The big sell for me was being able to install the GNU versions of everything.
Macports keeps everything in /opt, so you also never have to worry about it clobbering anything that MacOS expects to work in a certain way.
edit: some background on Macports vs Homebrew - it's basically a vi/emacs kind of a thing. Homebrew utilizes the MacOS system stuff a fair amount, and installs everything to /usr/local. Macports tries to keep everything fully separate, and installs into /opt.
My personal experiences with Homebrew weren't great, but others will probably have the opposite opinion.
This means:
1) It is a security hole; any application can now modify system-wide applications at any time.
2) You can't have multiple users able to use homebrew.
I was expecting homebrew to be something similar to apt/yum/etc, but this makes it pretty fundamentally different.
How does Macports handle this? Does $USER still need write access to /opt?
eg for htop: `sudo port install htop`
First thing I installed in the mac store. Just like on linux, it just works and I get all my favourite tools.
Doesn't help much with dtrace though!
Alternative to strace would be dtruss, which is implemented through dtrace.
Example: `gsed` actually parses whitespace the way I think it will; the builtin `sed` does not.
to be fair, you should probably call the GNU behaviour "GNUisms". The BSD behaviour is the historical POSIX behaviour. The GNU behaviour is, in a twisted sense, the result of embrace, extend and extinguish by the GNU people :-)
I'd been using mostly Linux on the desktop since 1996, I manage servers for a living and couldn't live without a terminal. That's the nerdy side.
On the other hand, I was serious enough with photography and electronic music production to need best of breed tools, which are still largely Windows and Mac-only to this day.
There's also a time for everything, and there are days when regardless of your computing skills, you need your creative person/end user hat on and apps that "just work" to keep your right brain fully focused on the end result (e.g. "No thanks, I'm not going to get distracted compiling some Gimp plugin to get red-eye removal", which may or may not have changed since I last tried)
MacOS, in spite of its recent slight drop in quality, is still second to none in satisfying all these requirements at once.
This is the true 'unix philosophy.'
Science! :D
I love the approach of systematically going through and prodding everything to see what things do and whether they're actually required. I remember doing this on my Windows 95 machine, stripping down running tasks using Task Manager. Of course, in Windows 95, if you killed the wrong task the system would just reboot... :P
On servers I find atop to actually be a better tool for finding issues that happen incrementally and not an obvious issue. I think that atop and htop both are very complimentary.
"Atop is an ASCII full-screen performance monitor for Linux that is capable of reporting the activity of all processes (even if processes have finished during the interval), daily logging of system and process activity for long-term analysis, highlighting overloaded system resources by using colors, etc. At regular intervals, it shows system-level activity related to the CPU, memory, swap, disks (including LVM) and network layers, and for every process (and thread) it shows e.g. the CPU utilization, memory growth, disk utilization, priority, username, state, and exit code. In combination with the optional kernel module netatop, it even shows network activity per process/thread."
Actually, the second number is the sum of the number of seconds that all cores on the machine have spent idle, so that number may be higher than the first one. Source: https://access.redhat.com/documentation/en-US/Red_Hat_Enterp...
My source (first result in Google) was this link https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-p... which looks like an older version of the documentation that does not have that last sentence.
du -macx ~ | egrep '^[0-9]{2}' | sort -n
egrep filter for files at least 10m ends up being a nice speed up, otherwise you end up spending most of the time sorting all the tiny files to the top while up writing hundreds of megabytes of /tmp/sortXXXX files in the process.What is it? How does it know that? How did I figure that out?
The second and third question are far more useful but usually not included in documentation or commentary.
I applaud the way you approached it - figuring out every single thing about a tool.
Also, I didn't know about 'od' command. Thanks again!
man od
You asked for two words ;).
echo hello | od
echo hello | od -c
Useful when you want to figure out the real contents of a file.
(can also dump characters and hexadecimal)
printf("The parent process is exiting now\n");
This should read child is exiting. printf("The child process is sleeping now\n");
This should read parent is sleeping.Overall, I really enjoyed the article.
...wat?
Is that actually a thing?
Useful bits/tricks to me:
# see what files a given program opens
strace PROGRAM_HERE 2>&1 | grep open
# get last pid
echo $!
# all sorts of useful commands and information on a given PID
ls -alh /proc/PID_HERE
# get a tree listing of all processes
pstree -a
# echo into a file using sudo
echo "some text here" | sudo tee -a FILE_PATH_HEREI'd really like to step up my game for GUI monitoring apps without having to choose between either terminal log spam, PyQT, or a web server. Ideally I'd have something like htop/wavemon/power top that I could stream compactly via ssh.
A server can perfectly run without dbus, accountsservice, logind, policykit and acpid. And, unlike he wrote, timesyncd NTP synchronization works well without dbus.
(Debian base has also cron and rsyslog running by default, for legacy reasons.)
$ strace -e open id 1000
open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
open("/etc/group", O_RDONLY|O_CLOEXEC) = 3
Well, by default yes. But if your system is configured to use NIS/YP or LDAP (through NSS/Name Service Switch), then these files won't have all the information (though they'll likely have a few, it's important to have local fallbacks in case of network issues!)A more generic tool is 'getent', which will query all the underlying databases for you. For example: "getent passwd" or "getent group".
Nevertheless, using strace to get a first approximation is an excellent exercise :)
$ strace -e open id 1000
...
open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
...
open("/usr/lib/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3
...
open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
open("/etc/group", O_RDONLY|O_CLOEXEC) = 3
...
Where nsswitch.conf informs it how to look up the information; the default on most systems being passwd: files
group: files
which tells it to the functions in /usr/lib/libnss_files.so to access the "passwd" (user) and "group" databases. libnss_files.so uses /etc/passwd and /etc/group respectively for these.If I recall correctly the CPU usage would still be 100% but could go up to 200% if both cores are fully used.
If only the UI had something like hover-tips to show what each field actually means...
Goodbye polkit!
Pretty OT, but does anyone know if that's true (or worthwhile?)?
It uses a session tracker (used to be Consolekit, these days it is systemd-logind) to tell if something is running under an active user session and, and checks that against a bunch of rules (stored in XML, natch) to see if what is being attempted is allows (and if not, spawn a password prompt so the user can elevate their privileges).
If you want to do anything "complicated" like powering down your PC by clicking a button in your DE of choice you need polkit (and entourage) to be present these days.
Its one of those CADT things that seems to lead to "year of the (linux) desktop" never happening.
You can use your mouse/TrackPoint in htop to click on menu options, processes etc...
Really excellent example of showing your work!
Has disk, network, proc, mem, cpu, etc. all wrapped up in a a curses interface. very slick and useful.
Good job.