2010-02-01 16 views
8

Bir işlem çöktüğünde OS X'de çekirdek bir dökümü nasıl oluşturacağımı biliyorum, ancak gerçekten ihtiyacım olan şey bir işleme eklenmek, bir çekirdek dökümü oluşturmak, ardından bu işlemi (devam etmeden) devam ettirmektir.OS X: İşlemi aşağı çekmeden çekirdek dökümü oluşturulsun mu?

Uzun zaman önce (belki bir buçuk yıl önce) bunu yapacak C kodu vardı ... Bir işleme bağlanmak için tüm X X çekirdek kitaplıklarını kullandı, tüm iş parçacığı durumlarını ve belleğini okudu, ve bunu diskteki bir Mach-O dosyasına yazınız. Bu harika çalıştı (ve tam olarak aradığım şey), ama şimdi bu kodun benim için yaşadığını göremiyorum. Kodun OS X sistem internals kitabına bir şekilde benzediğini hatırlıyorum, ama bu sadece belirsiz bir hatırlama.

Bahsettiğim kodu herkes biliyor mu ve bana işaret edebilir mi? Değilse, bunu yapmak için iyi bir yol biliyor mu?

Düzenleme: İşte cevap.

Bilgi: sizin için yapacak http://osxbook.com/book/bonus/chapter8/core/

Programı: http://osxbook.com/book/bonus/chapter8/core/download/gcore-1.3.tar.gz

cevap

6

sana inanıyorum Özellikle this information

arıyoruz:

Yukarıdaki kod o karşılaştırarak ne olduğunu
/* UNIX Third Edition, circa early 1973 */ 
/* ken/sig.c */ 

core() 
{ 
int s, *ip; 
extern schar; 

/* u is the user area */ 
u.u_error = 0;   /* reset error code to "no error" */ 
u.u_dirp = "core";  /* file name to search for */ 
ip = namei(&schar, 1); /* do search; schar means it's a kernel string */ 

if (ip == NULL) {  /* failed to find */ 
    if (u.u_error)  /* because of some error */ 
     return(0);  /* so bail out */ 
    ip = maknode(0666); /* didn't exist; so create it */ 
} 

if (!access(ip, IWRITE)) { /* check "write" permission; 0 means OK */ 
    itrunc(ip);   /* truncate the core file */ 

    /* first we write the user area */ 
    u.u_offset[0] = 0;  /* offset for I/O */ 
    u.u_offset[1] = 0;  /* offset for I/O */ 
    u.u_base = &u;   /* base address for I/O (user area itself) */ 
    u.u_count = USIZE*64; /* bytes remaining for I/O; USIZE=8 */ 
    u.u_segflg = 1;  /* specify kernel address space */ 
    writei(ip);   /* do the write */ 

    /* 
    * u_procp points to the process structure 
    * p_size is the size of the process's swappable image (x 64 bytes) */ 
    */ 
    s = u.u_procp->p_size - USIZE; /* compute size left to write */ 

    /* 
    * This sets up software prototype segmentation registers to implement 
    * text(=0 here), data(=s here), and stack(=0 here) sizes specified. 
    */ 
    estabur(0, s, 0); 

    u.u_base = 0;   /* base address for I/O (start of space) */ 
    u.u_count = s*64;  /* s is in units of 64 bytes, so adjust */ 
    u.u_segflg = 0;  /* specify user address space */ 
    writei(ip);   /* do the write */ 
} 
iput(ip);     /* decrement inode reference count */ 
return(u.u_error==0);  /* done */ 
} 
+0

Bağlantılı gzip içindeki kod, bu yüzden doğru değil, ancak bağlantı (ve özellikle gcore gzip) tam olarak ne aradığımı. Teşekkürler! – LCC

+0

Bu bana daha dikkatli kopyalayıp yapıştırmayı öğretecek – mbarnett