Friday Jan 25, 2013

attaching to foreground process with strace in sh script

Apparently, it is not only the Oracle employees who use strace on foreground to process to get some info.

 

Locks, Latches, Mutexes and CPU usage | The Pythian Blog

To find out how it is implemented, I have traced Oracle foreground processes.

Last week, I had to do same in shell script for trouble shooting. Here are the lines.
I think one can do same with dtrace or debugger.

#!/bin/bash
( sleep 3
  ora_fg_pid=$(pgrep -P $(pgrep -P $$ sqlplus))
  lsof -p $ora_fg_pid > /tmp/$ora_fg_pid.strace
  echo -e "\n= = = =strace begings here= = = =\n" >> /tmp/$ora_fg_pid.strace
  strace -fp $ora_fg_pid >> /tmp/$ora_fg_pid.strace 2>&1 ) &
sqlplus -S scott/tiger <<EOF
--Wait for strace to attach.
execute user_lock.sleep(500)
--Do real stuff.
select * from dual
/
EOF



Thursday Jan 24, 2013

'jar' better than 'zip' ?

I recently learned that 'jar' can write to stdout. I think this tends to be overlooked for 3 reasons.

  1. 'jar' command line help doesn't suggest so unlike 'tar'.
  2. 'man jar' not possible on many installations.
  3. '-' doesn't mean stdout for 'jar' command.

Where 'man jar' runs, it shows below:

jar-The Java Archive Tool

To copy directories, first compress files in dir1
to stdout, then extract from stdin to dir2 (omitting the
-f option from both jar commands):

% (cd dir1; jar c .) | (cd dir2; jar x)

Firstly, I think this command will add MANIFEST to destination. One can do:

$ (cd dir1; jar cM .) | (cd dir2; jar x)

Secondly, I think better example would be over the network transfer.
This is what I do on Windows with PuTTy command line tool.
I can do same with 'tar.gz' but when I want to send this to someone, *.zip is handier.

$ plink myid@myserver 'cd data/ && jar cM *.txt *.csv' > allData.zip

So, although 'jar' and 'zip' creates archive in same format, jar is better for 2 reasons.

  1. 'zip' doesn't take directory name as argument
  2. No support for stdout. 'man zip' says there is some support but that's not for 'file system' archive.
About

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« January 2013 »
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
12
13
14
18
19
20
21
22
23
26
27
28
29
30
31
  
       
Today