This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.system segmentation fault
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: kowaltowski, nnorwitz, rhettinger
Priority: normal Keywords:

Created on 2004-08-25 12:25 by kowaltowski, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
threadproblem.tgz kowaltowski, 2004-08-25 12:25
Messages (8)
msg22210 - (view) Author: Tomasz Kowaltowski (kowaltowski) Date: 2004-08-25 12:25
System used: Linux Fedora Core 2.
Python version: Python 2.3.3 (#1, May  7 2004, 10:31:40)
------------------------------------------------

Depending on the build used for Java, its invocation
through os.system within a thread causes a segmentation
fault. The attached short program illustrates this problem.

Any Java class 'DoNothing.class' (also attached) in the
current directory will do. Notice that only the second
one of the two builds 04 and 05 causes this problem.

It migh be a Java problem but I tried the same thing
with pthreads in C, and no problems occured.

-- Tomasz Kowaltowski
msg22211 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-08-25 22:02
Logged In: YES 
user_id=33168

This sounds like an environment problem.  I'm guessing that
the stack is being blown and the kernel is killing the
process.  It's java that's dying, not python, correct?  

I don't have _05.  _04 works fine for me one Fedora 1.  Can
you use strace or gdb to try to determine what's happening?
 I'm not sure if anyone will be able to reproduce this
problem.  Can you also try starting java with options to
lower the the memory consumption, e.g., -Xss -Xmx.

From your shell you can also try raising stack size, etc
with ulimit.  This may get java to run ok.  -s changes the
stack size.  BTW, what does ulimit -a report?
msg22212 - (view) Author: Tomasz Kowaltowski (kowaltowski) Date: 2004-08-26 00:04
Logged In: YES 
user_id=185428

I tried all these things. Adding 'strace' to the command
line to be executed reports a segmentation fault which was
already expected because of the error code 11 printed by the
Python test program. 'ulimit -a' reports everything that
counts unlimited. I also tried Java memory options without
any success. You are right -- it is the java that is dying
not Python, but it only happens under this unusual circumstance.

It seems to me that if it were an environment problem it
would happen within any call of os.system. It happens
however only within Python threads: I tested both packages
'thread' and 'threading' and they both had the same
behavior. It does not happen if no threads are envolved, or
if threads are programmed in C.
msg22213 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-08-26 04:37
Logged In: YES 
user_id=33168

There's another possibility, but I'm not sure if it would
affect your build or not.  It's possible to set a smaller
stack size when creating a thread.  This would mean that
THREAD_STACK_SIZE is set.  If you look in
./Python/thread_pthread.h you will see the references. 
THREAD_STACK_SIZE is not set on my box.  

In your C test, did you pass NULL for the attributes or did
you do pthread_attr_init().  It's possible that is the
difference between your C test and python.  You might try
mucking in ./Python/thread_pthread.h to see if you can
determine what is happening.
msg22214 - (view) Author: Tomasz Kowaltowski (kowaltowski) Date: 2004-08-26 11:26
Logged In: YES 
user_id=185428

I did not find the file 'thread_pthread.h' under my
installation :-(.  My program in C is:

----------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *ExecuteCommand( void *ptr ) {
  char *command = ptr;
  int result = system(command);
  printf("Tested the command: %s; result =
%d\n",command,result);
  return NULL;
 } 

int main()
{
  pthread_t thread;
  pthread_create(&thread,NULL,ExecuteCommand,
       (void*)"/usr/java/j2sdk1.4.2_04/bin/java -cp .
DoNothing");
  pthread_join(thread,NULL);
  pthread_create(&thread,NULL,ExecuteCommand,
       (void*)"/usr/java/j2sdk1.4.2_05/bin/java -cp .
DoNothing");
  pthread_join(thread,NULL);
  return 0;
}
----------------------------------------------------------

It correctly prints 0 for both threads.
msg22215 - (view) Author: Tomasz Kowaltowski (kowaltowski) Date: 2004-09-08 18:45
Logged In: YES 
user_id=185428

Tested with the alpha version Python-2.4a3. It works properly!
msg22216 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-09-08 18:56
Logged In: YES 
user_id=80475

So, can this be closed as "out-of-date"?
msg22217 - (view) Author: Tomasz Kowaltowski (kowaltowski) Date: 2004-09-08 23:52
Logged In: YES 
user_id=185428

I guess so even though 2.4 is still alpha.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40822
2004-08-25 12:25:13kowaltowskicreate