목요일, 12월 14, 2006

linux network settting - route

http://kelp.or.kr/korweblog/stories.php?story=01/09/29/1007612


[ 네트워크 설정(두개의 랜카드 잡기) ]

1. IRQ, IO 번호 확인하기
$ cat /proc/pci
$ cat /proc/interrupts
$ cat /proc/ioports
$ dmesg

2. 부팅시 커널차원에서 인식 시키기
# Lan종류 + auto IRQ + auto IO + Lancard Device 번호의 순서로
$ vi /etc/lilo.conf
append="ether=0,0,eth0 ether=0,0,eth1" # PnP 인식
# append="ether=11,0x6100,eth0 ether=5,0x300,eth1" # 특정 인식

3. 일종의 드라이버인 모듈을 올리기
$ ls /lib/modules/kernel-version/net
$ modprobe ne.o io=0x300 irq=5
$ lsmod
$ rmmod
$ vi /etc/conf.modules
alias eth0 rtl8139 # PCI LANCard인 경우
alias eth1 ne # ISA LANCard인 경우
options ne io=0x300 irq=5
$ control-panel
Kernel Daemon Configuration -> Add -> Module Types eth -> OK ->
Which module type? eth1 -> Which module? ne -> OK ->
io=0x300 -> irq=5 -> Done

4. CMOS 차원에서의 IRQ 설정
# CMOS에서 네트워크의 PNP 기능을 없애서 내정 IRQ에 따른 출동을 피한다
[PNP/PCI Configuration]
PNP OS Installed : NO

5. 랜카드 차원에서의 IRQ 설정
# 물리적인 변경
LANCard Jumper move 10 -> 5
# 프로그램을 이용한 변경
Intel Ether Express Pro/10 PNP ISA e10disk.exe sofset2.exe
RealTek 8019 ISA PNP Ethernet(ne2000) rset8019.exe
# Setup
Plug and Play : Disable(or Juper less)
IO and IRQ setting

6. 모듈이 잡혔나 확인하기
$ uname -a # 커널버전 보기
$ ls /lib/modules/2.2.7/net
ne.o rt8139.o
$ /sbin/lsmod # 확실히 이부분이 올라와 있어야 한다
ne, rt8139 Module
$ modprobe ne io=0x300 irq=5 # 모듈을 로드 시키는 명령

7. 네트워크 등록정보 입력
# ip 설정
$ ifconfig # 기존 정보 보기
$ ifconfig eth0 192.168.10.5
$ ifconfig eth0 192.168.10.5 netmask 255.255.255.0 up # ip를 설정하는 명령
$ ifconfig eth0 down
# 라우팅 테이블 설정
$ route # 기존 정보 보기
$ netstat -nr # 기존 정보 보기
$ route add -net 192.168.10.0 netmask 255.255.255.0 dev eth0 # 추가 명령
$ route del default gw 192.168.255.255 eth0 # 삭제 명령
$ route add default gw 203.239.44.50 eth0
# 비주얼 제어판을 통한 설정
$ netcfg # 혹은 "$ linuxconf"
Default Gateway-203.239.44.50
Default Gateway Device-eth0
$ ifdown eth0; ifup eth0

8. 텍스트를 통한 Route, Gateway 설정
$ vi /etc/sysconfig/static-routes
# 각기 다른 게이트웨이를 쓸 경우 or skip
eth0 net 192.168.10.0 netmask 255.255.255.0 gw 192.168.10.1
eth1 net 192.168.11.0 netmask 255.255.255.0 gw 192.168.11.1
eth1:0 net 192.168.12.0 netmask 255.255.255.0 gw 192.168.12.1
# eth1:0 IP-Alias를 적용한 예
$ vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
IPADDR="192.168.100.1"
NETMASK="255.255.255.0"
NETWORK="192.168.100.0"
BROADCAST="192.168.100.255"
ONBOOT="yes"
BOOTPROTO="none"
GATEWAY="192.168.11.1" # 여기다 직접 게이트웨이를 쓸수있다.
GATEWAYDEV="eth1"
$ netcfg
$ ifdown eth1; ifup eth1
$ ifconfig

9. 네트워크를 설정하는데 쓰이는 파일들
# Basic file: hosts, resolv.conf, network, ifcfg-eth0
/etc/HOSTNAME
/etc/host.conf
/etc/hosts
/etc/resolve.conf
/etc/nsswitch.conf
/etc/conf.modules
/etc/sysconfig/network
/etc/sysconfig/static-routes
/etc/sysconfig/network-scripts/ifcfg-eth0

10. 네트워크 테스트 명령들
$ ping; traceroute; nslookup

월요일, 12월 11, 2006

Python memory leaks

Tracking Down Memory Leaks in Python


This Page Mostly Obsolete

Most of the stuff on this page is obsolete nowadays, since Python (since version 2.0, I think) now includes a cyclical-reference garbage collector. Leaks like this are still possible, but usually only because an older Python extension module (implementing a container type) is used, one that doesn't adhere to the new GC API.


Long-running processes have a nasty habit of exposing Python's Achilles' Heel: Memory Leaks created by cycles. (objects that point at each other, either directly or circuitously). Reference counting cannot collect cycles. Here's one way to create a cycle:

class thing:
pass

refcount(a) refcount(b)
a = thing() 1
b = thing() 1 1
a.other = b 1 2
b.other = a 2 2

del a 1 2
del b 1 1

Objects a and b have become immortal.

Large and complex systems may create non-obvious cycles. Here are a few quick hints to avoid various ones that I've run into:

  • Be careful with bound method objects. Bound methods are created whenever you refer to a method object through an instance. This happens safely every time you call a method; but a common programming style ('functional') passes such objects around, stores them in variables, etc... In one case storing a bound method in the object made it immortal. Either del this object manually, or change your code.
  • Tracebacks are very dangerous. To be really safe, del a traceback if you have a handle to it. Another good idea is to assign None to both sys.traceback and sys.exc_traceback.
    Tracebacks can capture a large number of objects, especially within Medusa. For example, any exception handler that is called from within the polling loop (no matter how deeply), should do something like this...
        def my_method (self):
    try:
    do_something()
    except:
    try:
    ei = sys.exc_info()
    [... report error ...]
    finally:
    del ei

    ...otherwise it will capture references to every object in the socket map. I have plugged some really bad leaks this way.
  • Keep track of your objects. Either keep a count of how many are around (in a __del__ method), or keep a dictionary of the addresses of all outstanding objects. This will help locate leaks.
    class thing:

    all_things = {}

    def __init__ (self):
    thing.all_things[id(self)] = 1

    def __del__ (self):
    del thing.all_things[id(self)]
    Here is a module that will let you resurrect leaked objects. Using this module should fill you with shame. Make sure no one is looking.
    for addr in thing.all_things.keys():
    r = resurrect.conjure (addr)
    # examine r...
  • Here's the easiest way to find leaking objects: examine the reference count of each of your class objects. This will be roughly equal to the number of extant instance objects.
    # -*- Mode: Python; tab-width: 4 -*-

    import sys
    import types

    def get_refcounts():
    d = {}
    sys.modules
    # collect all classes
    for m in sys.modules.values():
    for sym in dir(m):
    o = getattr (m, sym)
    if type(o) is types.ClassType:
    d[o] = sys.getrefcount (o)
    # sort by refcount
    pairs = map (lambda x: (x[1],x[0]), d.items())
    pairs.sort()
    pairs.reverse()
    return pairs

    def print_top_100():
    for n, c in get_refcounts()[:100]:
    print '%10d %s' % (n, c.__name__)

    if __name__ == '__main__':
    top_100()

Notes

An interface to malloc_stats() [Linux]

원문: http://www.nightmare.com/medusa/memory-leaks.html