Ady Wicaksono Daily Activities

Archive for July 14th, 2007

investigate a process on Linux server using lsof

leave a comment »

lsof – list open files is a very good tool for Linux Administrator

For example, you found a weird process

# ps aux

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     14668 48.2  0.1 243504  7448 ?        Sl   Jul10 3319:53 ./bin/StoreGrid

Hmmm… what is that, then you could simply check it using lsof

#  lsof  -p 14668
COMMAND     PID USER   FD   TYPE   DEVICE      SIZE     NODE NAME
StoreGrid 14668 root  cwd    DIR    253,0     32768 10977505 /home/storegrid/StoreGrid
StoreGrid 14668 root  rtd    DIR    253,0      4096        2 /
StoreGrid 14668 root  txt    REG    253,0  11812748 10977512 /home/storegrid/bin/StoreGrid
StoreGrid 14668 root  mem    REG    253,0     21704 38502449 /lib/libnss_dns-2.3.6.so
StoreGrid 14668 root  mem    REG    253,0     76272 38502417 /lib/libresolv-2.3.6.so
StoreGrid 14668 root  mem    REG    253,0    126576 38502420 /lib/ld-2.3.6.so
StoreGrid 14668 root  mem    REG    253,0   1481808 38502422 /lib/libc-2.3.6.so
StoreGrid 14668 root  mem    REG    253,0     16244 38502435 /lib/libdl-2.3.6.so
StoreGrid 14668 root  mem    REG    253,0    201032 38502439 /lib/libm-2.3.6.so
StoreGrid 14668 root  mem    REG    253,0    101680 38502429 /lib/libpthread-2.3.6.so
StoreGrid 14668 root  mem    REG    253,0     46640 38502452 /lib/libnss_files-2.3.6.so
StoreGrid 14668 root  mem    REG    253,0    733520 37828423 /usr/lib/libstdc++.so.5.0.7
StoreGrid 14668 root  mem    REG    253,0     40112 38502443 /lib/libgcc_s-4.0.2-20051126.so.1
StoreGrid 14668 root    0r   CHR      1,3               1938 /dev/null
StoreGrid 14668 root    1w   CHR      1,3               1938 /dev/null
StoreGrid 14668 root    2w   CHR      1,3               1938 /dev/null
StoreGrid 14668 root    3u  IPv4 34761557                TCP *:32005 (LISTEN)
StoreGrid 14668 root    4u  IPv4 34761558                UDP *:58304
StoreGrid 14668 root    5u  IPv4 34761559                UDP *:17254
StoreGrid 14668 root    6u  IPv4 34761560                UDP *:6363
StoreGrid 14668 root    7u  IPv4 69369170                TCP xxxxxx:37402->yyyyy:32004 (ESTABLISHED)
StoreGrid 14668 root    8u  IPv4 34761564                UDP *:6364
StoreGrid 14668 root   12u  IPv4 34761590                UDP *:32006

Got it, I found binary executables, socket information, and many other information on this process. Actually this lsof tool read and process information from “/proc” pseudo filesystem on Linux, for pid 14668, then this tool will investigate /proc/14668 directory content.

# ls -l /proc/14668
total 0
dr-xr-xr-x    5 root root 0 Jul 10 04:15 ./
dr-xr-xr-x  172 root root 0 Jul  5 04:36 ../
dr-xr-xr-x    2 root root 0 Jul 14 23:04 attr/
-r--------    1 root root 0 Jul 14 23:04 auxv
-r--r--r--    1 root root 0 Jul 14 21:19 cmdline
-r--r--r--    1 root root 0 Jul 14 23:04 cpuset
lrwxrwxrwx    1 root root 0 Jul 14 22:47 cwd -> /home/storegrid/StoreGrid/
-r--------    1 root root 0 Jul 14 23:04 environ
lrwxrwxrwx    1 root root 0 Jul 14 08:50 exe -> /home/storegrid/bin/StoreGrid*
dr-x------    2 root root 0 Jul 14 22:47 fd/
-rw-r--r--    1 root root 0 Jul 14 23:04 loginuid
-r--------    1 root root 0 Jul 14 22:47 maps
-rw-------    1 root root 0 Jul 14 23:04 mem
-r--r--r--    1 root root 0 Jul 14 23:04 mounts
-r--------    1 root root 0 Jul 14 23:04 mountstats
-rw-r--r--    1 root root 0 Jul 14 23:04 oom_adj
-r--r--r--    1 root root 0 Jul 14 23:04 oom_score
lrwxrwxrwx    1 root root 0 Jul 14 22:47 root -> //
-r--r--r--    1 root root 0 Jul 14 23:04 schedstat
-r--------    1 root root 0 Jul 14 23:04 smaps
-r--r--r--    1 root root 0 Jul 14 21:19 stat
-r--r--r--    1 root root 0 Jul 14 08:50 statm
-r--r--r--    1 root root 0 Jul 14 21:19 status
dr-xr-xr-x   23 root root 0 Jul 10 04:15 task/
-r--r--r--    1 root root 0 Jul 14 23:04 wchan

lsof is also able to detect port UDP/TCP activity, for example from “netstat” you get weird information

#netstat -nl

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:1                   0.0.0.0:*                   LISTEN

Hey, what server running on port TCP number 1???

Find it

#  lsof -i TCP:1
COMMAND    PID USER   FD   TYPE DEVICE SIZE NODE NAME
portsentr 3646 root    0u  IPv4  10777       TCP *:tcpmux (LISTEN)

# lsof -p 3646
COMMAND    PID USER   FD   TYPE DEVICE    SIZE     NODE NAME
portsentr 3646 root  cwd    DIR  253,0    4096        2 /
portsentr 3646 root  rtd    DIR  253,0    4096        2 /
portsentr 3646 root  txt    REG  253,0   30128 37818458 /usr/sbin/portsentry
portsentr 3646 root  mem    REG  253,0  126576 38502420 /lib/ld-2.3.6.so
portsentr 3646 root  mem    REG  253,0 1481808 38502422 /lib/libc-2.3.6.so
portsentr 3646 root    0u  IPv4  10777              TCP *:tcpmux (LISTEN)
portsentr 3646 root    1u  IPv4  10779              TCP *:sunrpc (LISTEN)

Got it….. nice tool right?

Advertisements

Written by adywicaksono

July 14, 2007 at 1:09 pm

Posted in Linux

Calendar

with one comment

Hey, do you need a javascript for calendar?

Try it http://www.dynarch.com/demos/jscalendar/

Written by adywicaksono

July 14, 2007 at 12:43 pm

Posted in Web Programming

GSM Mobile Application Part (MAP) – Part 1

with 8 comments

What is MAP? From Wikipedia definition I found

The Mobile Application Part (MAP) is an SS7 protocol which provides an application layer for the various nodes in GSM and UMTS mobile core networks and GPRS core networks to communicate with each other in order to provide services to mobile phone users. The Mobile Application Part is the application-layer protocol used to access the Home Location Register, Visitor Location Register, Mobile Switching Center, Equipment Identity Register, Authentication Centre, Short message service center and Serving GPRS Support Node.

Last time I worked at a company that develop their own SMSC, HLR, VLR, and other telco product. One of my job is developing GSM-MAP Driver focusing on SMSC MAP stuff. OK, let’s talk about MAP 🙂

What you need to know first is SS7. If you’re familiar with TCP/IP stack, it will not really hard to understand, but maybe yes hard to figure :D.

Just for additional information, let me give you a snapshot log what happened when SMSC want to deliver SMS to your mobile phone:

2006-12-11 13:40:48.789	491	MSU	UDT 	8842	403	Begin	00010021		 MAP OP: ForwardShortMessage	
  MTP2                                                                             MSU
   [.111 1011] BSN                                                                  123
   [1... ....] BIB                                                                  1
   [.111 1110] FSN                                                                  126
   [1... ....] FIB                                                                  1
   [..11 1111] Li                                                                   63
  MTP3
   [10.. ....] NI - Network Indicator                                               National network (2)
   [..00 ....] Spare                                                                0
   [.... 0011] SI - Service Indicator                                               SCCP (3)
   DPC                                                                              8842 (Dec) - 228a (Hex) - Osaka
   OPC                                                                              0403 (Dec) - 0193 (Hex)
   SLS                                                                              05 (Dec) - 05 (Hex)
  SCCP                                                                             Msg=UDT unitdata
   [0000 1001] Message Type                                                         UDT unitdata
   Protocol class                                                                   80 (Hex)
   [1000 ....] Message handling                                                     Return message on error
   [.... 0000] Protocol Class                                                       Class 0
   Called party address
     Length                                                                           10
     [.0.. ....] Routing indicator                                                    Routing based on Global Title
     [..01 00..] Global Title included                                                includes translation type, numbering plan, encoding scheme and nature of address indicator
     [.... ..1.] Subsystem number                                                     In use
     [.... ...0] Signalling point code indicator                                      Not in use
     [0000 1000] Affected Subsystem                                                   MSC
     [0000 0000] Translation type                                                     Not used
     [0001 ....] Numbering plan                                                       ISDN/telephony numbering plan (Rec E.163/E.164)
     [.... 0010] Encoding scheme                                                      BCD even number digits
     [.000 0100] Nature of address indicator                                          International number
     Called address                                                                   4540590016
   Calling party address
     Length                                                                           10
     [.0.. ....] Routing indicator                                                    Routing based on Global Title
     [..01 00..] Global Title included                                                includes translation type, numbering plan, encoding scheme and nature of address indicator
     [.... ..1.] Subsystem number                                                     In use
     [.... ...0] Signalling point code indicator                                      Not in use
     [0000 1000] Affected Subsystem                                                   MSC
     [0000 0000] Translation type                                                     Not used
     [0001 ....] Numbering plan                                                       ISDN/telephony numbering plan (Rec E.163/E.164)
     [.... 0010] Encoding scheme                                                      BCD even number digits
     [.000 0100] Nature of address indicator                                          International number
     Calling address                                                                  4531899997
   Data
     Length                                                                           90
  TCAP
   Message Type                                                                     Begin (2)
   Transaction Portion
     OrigID                                                                           '00 01 00 21' Hex
   DialoguePortion
     External
     OBJECT IDENTIFIER                                                                0.0.17.773.1.1.1
                                                                                      itu-t(0) rec(0) q(17) (773) as(1) dialogue pdu(1) Version1(1)
     Single ASN.1
     DialogueRequest
     OBJECT IDENTIFIER                                                                0.4.0.0.1.0.25.2
                                                                                      itu-t(0) id-org(4) etsi(0) mobileDomain(0) gsm-network(1) appContext(0)
                                                                                      shortMsgMT-RelayContext(25).version2(2)
   Components Portion
     Component                                                                        MAP (Component 1)
     Component type                                                                   Invoke
     Invoke-ID                                                                        1
  MAP                                                                              (Component 1)
   [0010 1110] Operation                                                            ForwardShortMessage (46 Dec)
     SM-RP-DA
       [1000 0000] IMSI                                                                 MCC:238 MNC:07 MSIN:0000000007
     SM-RP-(D)OA
       [1000 0100] serviceCentreAddress
         AddressString
         [1... ....] Extension                                                            no extension
         [.001 ....] Nature of address indicator                                          International number
         [.... 0001] numbering plan indicator                                             ISDN/Telephony Num plan.E.164
         Address digits                                                                   4531899997
     SM-RP-UI
       [0000 0100] SignalInfo                                                           '240a91541308007000006021112104540004d4f29c0e'Hex
     SMS
       [0000 0100] SMS_V2_GSM03.04
       [.... ..00] TP-MTI                                                               SMS-DELIVER (SC to MS)
       [.... .1..] TP-MMS                                                               No more messages are waiting for the MS in this SC
       [...0 0...] spare
       [..1. ....] TP-SRI                                                               A status report will be returned to the SME
       [.0.. ....] TP-UDHI                                                              The TP-UD field contains only the short message
       [0... ....] TP-RP                                                                TP-Reply-Path parameter is not set in this SMS-SUBMIT/DELIVER
       TP-OA Originating-Address
       [.001 ....] Type of number                                                       International number
       [.... 0001] Numbering plan id                                                    ISDN/Telephony (E.164/E.163)
       Number                                                                           4531800007
       TP-PID Protocol-Identifier
       [00.. ....]                                                                      Assigns bits 0..5 telematic
       [..0. ....]                                                                      no interworking, but SME-to-SME protocol
       [...0 0000] SM-AL protocol                                                       Unknown
       TP-DCS Data-Coding-Scheme
       [00.. ....] Coding group                                                         General Data Coding Indication
       [..0. ....]                                                                      uncompressed
       [...0 ....]                                                                      Bit 1 & 0 have no message class meaning
       [.... 00..] Alphabet                                                             Default alphabet-7bit
       TP-SCTS Service-Center-Time-Stamp
       year                                                                             06
       month                                                                            12
       day                                                                              11
       hour                                                                             12
       minute                                                                           40
       second                                                                           45
       time-zone GMT                                                                    +00 (0 quarters)
       TP-UDL User-Data-Length                                                          4
       TP-UD User-Data
       TP-User-Data                                                                     Test
FB FE 3F 83 8A E2 64 50 09 80 03 0D 17 0A 12 08 00 12 04 54
04 95 00 61 0A 12 08 00 12 04 54 13 98 99 79 5A 62 58 48 04
00 01 00 21 6B 1A 28 18 06 07 00 11 86 05 01 01 01 A0 0D 60
0B A1 09 06 07 04 00 00 01 00 19 02 6C 34 A1 32 02 01 01 02
01 2E 30 2A 80 08 32 08 07 00 00 00 00 F7 84 06 91 54 13 98
99 79 04 16 24 0A 91 54 13 08 00 70 00 00 60 21 11 21 04 54
00 04 D4 F2 9C 0E

See u…

Written by adywicaksono

July 14, 2007 at 12:28 pm

Posted in Telco - GSM

Length of Array in C

with one comment

Q: How to count length of array in C/C++?

A:

———- cut here ———-
typedef struct {
int x;
int y;
}ok ;

int main(){

ok i [] = {
{1,2},
{3,4}
};
printf(“SIZE: %d\n”,sizeof (i) / sizeof (*i));
return 0;
}

==> Size = sizeof(i)/sizeof(*i)

Written by adywicaksono

July 14, 2007 at 11:51 am

Posted in Programming

Scripting Language for Mobile Phone

leave a comment »

Programming on Symbian is difficult compared to many other programming fields. Using C++ as main programming language with many boundaries, different memory management, and many other rules, it’s not easy for you even just to create your first HelloWorld application. Thanks, today there’re many choices for creating Symbian application which is more simpler. Python for S60 is one of them. Actually, I knew it since first release for S60 1st Edition, already tried it and so far so good.

Using this scripting language, you can access many features from Symbian OS itself, like get IMEI information, access Symbian DBMS, SMS Inbox, and many other which commonly is not accessible through J2ME.

Just make a try… 🙂

Written by adywicaksono

July 14, 2007 at 11:11 am

Posted in Mobile