Spawned process memory size

Using QNX 6.1.A

I have a process that is spawned by a parent. The spawned process has a
large data structure of the form:

typedef struct
{
unsigned long size;
int type;
int number;
float data;
unsigned short image_data[NUMBER];
} Image_messageT;


When NUMBER = 60000 everything works fine. If I increase NUMBER to 76800
then the spawned process immediately terminates abnormally. Using dumper
for the spawned process gives the message:

Program terminated with signal 11, segmentation violation

Also if I remove the declaration of the image_message structure in the
spawned process it works fine.

Is this declaration exceeding the memory size of a spawned process? If so
can this memory size be increased to accomodate it? If this is not the
problem can anyone think what it might be?

Thanks.

Paul.

Paul Jones <paul.jones@bnc.ox.ac.uk> wrote:

Using QNX 6.1.A

I have a process that is spawned by a parent. The spawned process has a
large data structure of the form:

typedef struct
{
unsigned long size;
int type;
int number;
float data;
unsigned short image_data[NUMBER];
} Image_messageT;



When NUMBER = 60000 everything works fine. If I increase NUMBER to 76800
then the spawned process immediately terminates abnormally. Using dumper
for the spawned process gives the message:

Program terminated with signal 11, segmentation violation

Also if I remove the declaration of the image_message structure in the
spawned process it works fine.

Is this declaration exceeding the memory size of a spawned process? If so
can this memory size be increased to accomodate it? If this is not the
problem can anyone think what it might be?

What processor is this occurring on?

Is the variable declared of this struct a stack variable or a global
variable?

When this process dies, do you get a dump file? If you load the
dump file, where has it crashed? Before calling main()? Somewhere
after calling main()?

There isn’t/shouldn’t be a memory size for spawned processes.

For instance, try the following simple program:

#include <stdio.h>

typedef struct bigbuf {
char buf[100000];
} bigbuft;

bigbuft buf1;

int main()
{
bigbuft buf2;

buf2.buf[9999] = buf1.buf[500];

printf(“hello\n”);

}

Compile & run it from the command line. (Or, spawn it from your
“spawner” program – though the shell uses spawn to start programs
too.)

It should run just fine.

(Well, at least it does for me on my test machine – but my test is
6.2 x86, not 6.1.)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

David,
Thanks for the reply. I have found the problem. The structure
was being declared in a thread created inside the process. The default for
a thread is a 4K stack. I increased it with a call to
pthread_attr_setstacksize().

Paul.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:agva01$qo6$1@nntp.qnx.com

Paul Jones <> paul.jones@bnc.ox.ac.uk> > wrote:
Using QNX 6.1.A

I have a process that is spawned by a parent. The spawned process has a
large data structure of the form:

typedef struct
{
unsigned long size;
int type;
int number;
float data;
unsigned short image_data[NUMBER];
} Image_messageT;


When NUMBER = 60000 everything works fine. If I increase NUMBER to
76800
then the spawned process immediately terminates abnormally. Using
dumper
for the spawned process gives the message:

Program terminated with signal 11, segmentation violation

Also if I remove the declaration of the image_message structure in the
spawned process it works fine.

Is this declaration exceeding the memory size of a spawned process? If
so
can this memory size be increased to accomodate it? If this is not the
problem can anyone think what it might be?

What processor is this occurring on?

Is the variable declared of this struct a stack variable or a global
variable?

When this process dies, do you get a dump file? If you load the
dump file, where has it crashed? Before calling main()? Somewhere
after calling main()?

There isn’t/shouldn’t be a memory size for spawned processes.

For instance, try the following simple program:

#include <stdio.h

typedef struct bigbuf {
char buf[100000];
} bigbuft;

bigbuft buf1;

int main()
{
bigbuft buf2;

buf2.buf[9999] = buf1.buf[500];

printf(“hello\n”);

}

Compile & run it from the command line. (Or, spawn it from your
“spawner” program – though the shell uses spawn to start programs
too.)

It should run just fine.

(Well, at least it does for me on my test machine – but my test is
6.2 x86, not 6.1.)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Paul Jones <paul.jones@bnc.ox.ac.uk> wrote:

Thanks for the reply. I have found the problem. The structure
was being declared in a thread created inside the process. The default for
a thread is a 4K stack. I increased it with a call to
pthread_attr_setstacksize().

I find that putting that much data on the stack is just asking for trouble.

Instead of:

typedef struct
{
unsigned long size;
int type;
int number;
float data;
unsigned short image_data[NUMBER];
} Image_messageT;

I prefer to do this:

typedef struct
{
unsigned long size;
int type;
int number;
float data;
unsigned short image_data[0];
} Image_messageT;

…and then in the code instead of…

void myfunc(void)
{
Image_messageT fred;


}

I do

void myfunc(void)
{
Image_messageT *fred;

fred = malloc( sizeof(Image_messageT) + NUMBER * sizeof(unsigned short) );


}

that gives me the same structure, but keeps it off the stack, and eliminates
any of the issues that come with placing large amounts of data on the stack.

Cheers,
Camz.