My Solaris Cannot Fork
Although I was still active in my ssh login session, I was not able to run any command (like ls, w, cat...) 'cos they need to fork out processes from the shell. In this kind of scenario, you are basically handicapped. After some searching on the web, I found this link that showed you how to simulate other commands using shell built-in functions. With this, there is no forking involved. Basically it take advantage of loop construct and file redirection.
I am trying to show you how you can do a few things with built-in functions that may help you to save the day. I believe it can do more than what I described here. BTW, they run on Korn shell.
Equivalent of "cat":
my_cat() { while read line do echo $line done < $1 }
Equivalent of "wc":
my_wc() { nl=0 nw=0 nc=0 in=$1 while read line do ((nl=nl+1)) set -- $line ((nw=nw+$#)) ((nc=nc+${#line}+1)) done < $in echo "\t$nl\t$nw\t$nc\t$in" }
Equivalent of "ls"
my_ls() { my_ls() { echo $@ | while read i do echo $i done }
In such situation, you may want to count the total number of files opened in the system (based on /proc/*/fd/*, exclude stdin/stdout/stderr):
my_nfd() { n=0 for fd in /proc/[0-9]*/fd/* do # exclude stdin/stdout/stderr (0/1/2) if [ ${fd##*/} -gt 2 ]; then ((n=n+1)) fi done echo $n }
Labels: shell script, Solaris, unix
0 Comments:
Post a Comment
<< Home