Thursday, March 29, 2012
Thursday, March 22, 2012
Static & dynamic compilation of C code
Static compilation
===================
[root@vilalin05 src]# gcc -m64 -static -o server server.c
confirmation check :
1]execute file command
[root@vilalin05 src]# file server
server: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, statically linked, for GNU/Linux 2.6.9, not stripped
[root@vilalin05 src]#
2]execute ldd command
[root@vilalin05 src]# ldd server
not a dynamic executable
[root@vilalin05 src]#
Dynamic compilation
===================
[root@vilalin05 src]# gcc -m64 -o server server.c
confirmation check:
1]
[root@vilalin05 src]# file server
server: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
2]
[root@vilalin05 src]# ldd server
libc.so.6 => /lib64/libc.so.6 (0x000000386da00000)
/lib64/ld-linux-x86-64.so.2 (0x000000386d600000)
[root@vilalin05 src]#
||END||
===================
[root@vilalin05 src]# gcc -m64 -static -o server server.c
confirmation check :
1]execute file command
[root@vilalin05 src]# file server
server: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, statically linked, for GNU/Linux 2.6.9, not stripped
[root@vilalin05 src]#
2]execute ldd command
[root@vilalin05 src]# ldd server
not a dynamic executable
[root@vilalin05 src]#
Dynamic compilation
===================
[root@vilalin05 src]# gcc -m64 -o server server.c
confirmation check:
1]
[root@vilalin05 src]# file server
server: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
2]
[root@vilalin05 src]# ldd server
libc.so.6 => /lib64/libc.so.6 (0x000000386da00000)
/lib64/ld-linux-x86-64.so.2 (0x000000386d600000)
[root@vilalin05 src]#
||END||
Thursday, March 8, 2012
Create a binary file with some data using Perl
Create a binary file with some data using Perl:
#!/usr/bin/perl
open(FH,"> /tmp/binfile") || die "\nUnable to open file for write mode.\n";
for($i = 0;$i<100;$i++){
$bits = pack( "sai", 200, "TEST", 300000 );
print FH $bits;
}
where
s A signed short (16-bit) value. (200)
a A string with arbitrary binary data, will be null padded. (TEST)
i A signed integer value. (300000)
#!/usr/bin/perl
open(FH,"> /tmp/binfile") || die "\nUnable to open file for write mode.\n";
for($i = 0;$i<100;$i++){
$bits = pack( "sai", 200, "TEST", 300000 );
print FH $bits;
}
where
s A signed short (16-bit) value. (200)
a A string with arbitrary binary data, will be null padded. (TEST)
i A signed integer value. (300000)
Hashes in shell
Might be one of the way to use “hashes” in ksh
It’s somewhat difficult to use hashes in bash[3* version], however easily possible in korn shell with below code !
#!/bin/ksh
typeset -A newmap
name="mandar"
id="111515"
newmap["name"]=$name
newmap["id"]=$id
echo "${newmap["id"]}"
Might be one of the way to use “array_push” method in ksh:
[root@cllin11 ~]# vim array_push.sh
#!/bin/ksh
typeset -A newmap
map_cnt=0
policy_list=`/usr/openv/netbackup/bin/admincmd/bppllist -l`
for pol in $policy_list
{
newmap["$map_cnt"]=$pol
map_cnt=` expr $map_cnt + 1 `
}
i=0
while [ $i -lt $map_cnt ]
do
echo "${newmap["$i"]}"
i=` expr $i + 1 `
done
Subscribe to:
Posts (Atom)