Tuesday, December 10, 2013

Process and open files

There are situations where we may need to know :
1. Which files are opened by a given process
2. Which process is using a given file

If we are given a process and we need to find out the files opened by it then we can simply use
#pfiles <pid>

And if a file is given an we need to know which process has opened it then use
#fuser <file>

Convert shell script in binary

There are times when you want to hide the contents of your shell script to binary form so that it may not be read by others.
One such utility is called "shcomp"

shcomp - compile a ksh93 shell script

Using this utility you can compile/convert your ksh script to a binary script.

Tuesday, December 3, 2013

Run command in Parallel

We can run shell commands in parallel which can be very useful to utilize the power of system
Today system come with multiple CPU and each CPU has multiple cores.
 To utilize the full power of these CPUs you can run shell commands in parallel of different CPU at the same time.

Below is just a small example shows dd command running in parallel using pipe "|" on different CPU :


 # dd if=dev/zero of=/dev/null | dd if=dev/zero of=/dev/null

 #prstat
PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP
5080 root     1636K 1040K cpu0    40    0   0:00:24  17% dd/1
5079 root     1636K 1040K cpu3    40    0   0:00:24  17% dd/1

Similarly,
we can gunzip and tar a file :
# gzcat  <file.tar.gz> | tar -xvf -
# gzcat  <file.tar.gz> | tar -xvf -