You are not logged in.

#1 2017-11-16 03:32:12

m-seven
Member
Registered: 2017-11-15
Posts: 3

why pstack does not printf ?

Hi all ,

I write a deadlock case to test how to using pstack,

when run pstack <pid>  ,it shows :

Could not attach to target 28378: Operation not permitted.
detach: No such process

so  I changes as super user to run pstack:

28378: ./deadlock
(No symbols found in )
(No symbols found in /lib/i386-linux-gnu/libc.so.6)
(No symbols found in /lib/ld-linux.so.2)
crawl: Input/output error
Error tracing through process 28378
0xb779fce5: _fini + 0x25d51

so why pstack does not work ?

there  is  the deadlock case code:

#include <unistd.h> 
#include <pthread.h> 
#include <string.h> 
 
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; 
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER; 
pthread_mutex_t mutex3 = PTHREAD_MUTEX_INITIALIZER; 
pthread_mutex_t mutex4 = PTHREAD_MUTEX_INITIALIZER; 
 
static int sequence1 = 0; 
static int sequence2 = 0; 
 
int func1() 
{ 
   pthread_mutex_lock(&mutex1); 
   ++sequence1; 
   sleep(1); 
   pthread_mutex_lock(&mutex2); 
   ++sequence2; 
   pthread_mutex_unlock(&mutex2); 
   pthread_mutex_unlock(&mutex1); 
 
   return sequence1; 
} 
 
int func2() 
{ 
   pthread_mutex_lock(&mutex2); 
   ++sequence2; 
   sleep(1); 
   pthread_mutex_lock(&mutex1); 
   ++sequence1; 
   pthread_mutex_unlock(&mutex1); 
   pthread_mutex_unlock(&mutex2); 
 
   return sequence2; 
} 
 
void* thread1(void* arg) 
{ 
   while (1) 
   { 
       int iRetValue = func1(); 
 
       if (iRetValue == 100000) 
       { 
           pthreadexit(NULL); 
       } 
   } 
} 
 
void* thread2(void* arg) 
{ 
   while (1) 
   { 
       int iRetValue = func2(); 
 
       if (iRetValue == 100000) 
       { 
           pthreadexit(NULL); 
       } 
   } 
} 
 
void* thread3(void* arg) 
{ 
   while (1) 
   { 
       sleep(1); 
       char szBuf[128]; 
       memset(szBuf, 0, sizeof(szBuf)); 
       strcpy(szBuf, "thread3"); 
   } 
} 
 
void* thread4(void* arg) 
{ 
   while (1) 
   { 
       sleep(1); 
       char szBuf[128]; 
       memset(szBuf, 0, sizeof(szBuf)); 
       strcpy(szBuf, "thread3"); 
   } 
} 
 
int main() 
{ 
   pthread_t tid[4]; 
   if (pthread_create(&tid[0], NULL, &thread1, NULL) != 0) 
   { 
       exit(1); 
   } 
   if (pthread_create(&tid[1], NULL, &thread2, NULL) != 0) 
   { 
       exit(1); 
   } 
   if (pthread_create(&tid[2], NULL, &thread3, NULL) != 0) 
   { 
       exit(1); 
   } 
   if (pthread_create(&tid[3], NULL, &thread4, NULL) != 0) 
   { 
       exit(1); 
   } 
 
   sleep(5); 
   //pthread_cancel(tid[0]); 
 
   pthread_join(tid[0], NULL); 
   pthread_join(tid[1], NULL); 
   pthread_join(tid[2], NULL); 
   pthread_join(tid[3], NULL); 
 
   pthread_mutex_destroy(&mutex1); 
   pthread_mutex_destroy(&mutex2); 
   pthread_mutex_destroy(&mutex3); 
   pthread_mutex_destroy(&mutex4); 
 
   return 0; 
}

Last edited by m-seven (2017-11-16 03:39:34)

Offline

#2 2017-11-16 03:34:30

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: why pstack does not printf ?

Read the Code of Conduct and use code tags when pasting to the boards: https://wiki.archlinux.org/index.php/Co … s_and_code


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2017-11-16 03:40:45

m-seven
Member
Registered: 2017-11-15
Posts: 3

Re: why pstack does not printf ?

jasonwryan wrote:

Read the Code of Conduct and use code tags when pasting to the boards: https://wiki.archlinux.org/index.php/Co … s_and_code

I  have add the tag ~~~~

could you please tell  how to setup the auto mails to remind me that someone have reply the post ?

Offline

#4 2017-11-16 04:37:38

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: why pstack does not printf ?

In your profile, select subscribe to all threads that you start. Or, hit the subscribe button on the bottom right of the text box.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB