Context: an AIX lpar with very low memory (no forking possible, so only shell's builtins (cd, echo, kill) will work). I can have a (hmc) console to it, but I need a better way to start freing memory in AIX, when memory is too low to even allow you to do a "ps -ef". (I have a way, but it is a way to randomly kill existing pids. I need to have more info on the PID I can kill, so I can choose an unimportant PID)
I want to know :
- How could I see the content of files using only ksh' builtins
- and the ultimate goal: what file's content could I look at, using only builtins, to choose the pids to kill, so that I only kill "mundane" process, (when I killed enough PIDs, I will then be able to "ps -ef" "netstat -rn" etc, and "ps" should still show the "important" processes)
What I already know:
I can log in the console (ssh hscroot@hmc, vtmenu, choose the lpar with OutOfMemory problems, log as root, and, after a while (2-5 minutes) and several complaints that ksh can't fork commandes in /etc/profile, I get to a (ksh) prompt.
Now I can simulate "ls" to see what /proc/PID# directory exists:
cd /proc ; echo *will get me the list of still running PIDs. (usually I'll see 0, 1(init), which are not to be killed, and also a whole bunch of other PIDs, with little indication of what process they run (ksh? syncd? ls? java?).
I can also :
kill some pids hereto free memory enough (kill is a builtin in ksh (or bash!), so no need to fork to use it) and when I killed enough PIDs, I am then able to then do a
netstat -rnetc, allowing me to get the state of the server before I
shutdown -rFto reboot it from the lpar itself (This will sync, close filesystems, etc. Note that the alternative, a reboot from the HMC, is usually not possible (as it probably tries to fork some commands), unless you add "--immed", which is like powering off directly and is not advisable as it can cause filesystem problems, causing sometimes very lengthy fsck when restarting the lpar).
- killing some PIDs and runnign the shutdown: allow me to get some "ps -ef" ideas of what was running and needs to restart, get the routes (in case the static routes don't match), and shutdown "more gracefully", preserving the filesystem and avoiding lengthy fsck when it starts-up.)
But I need your help to also:
See the content of some files! (for ex: to be able to see the pid of some of the pid files in /var/run/*.pid, I'd do :
cd /var/runand then
echo *pidto get the list of pid files, but then, with only builtins of ksh (remember: no forking!) how can I get the content of one of those files?). The same trick could also help to get some infos underneath /proc/PID#/ ..., maybe allowing me to also choose the right PID to kill)
choose PIDs "wisely" using the above (or whatever trick you can have)
Precision: Bonus points if your trick works with this version ksh builtins:
prompt# strings /usr/bin/ksh | grep '\..*\.' | grep builtin 0@(#)27 18.104.22.168 src/bos/usr/bin/ksh/builtin.c, cmdksh, bos61Z, z2013_29A2 7/5/13 00:10:52