473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Question about fprintf

Hi,

I have a program, where involves creation of a thread with stack size
of 16k(minimum stack size). There is an fprintf statement in the
created thread code.
I see that there is a core dump occuring at fprintf.

code snippet :
************************************************** *******************************
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
void func(void *);

#define OUTSTREAM stderr

pthread_attr_t attr;
main()
{
pthread_t p[10];
void *exitstatus;
int i;
pthread_attr_init(&attr);
if(pthread_attr_setstacksize (&attr,16ul * 1024ul))
{
printf("\n\n\nfailed to set stack size");
}
pthread_create(&p[i],&attr,func,NULL);

sleep(1000);

}
void func(void *ptr)
{
int i ;
char str[100];
fprintf(OUTSTREAM," FIRST :: Thread Created and here is fprintf
\n");
}

core dump trace in gdb:
Starting program: /users/a21313/fprintf/ftest_clean
[Thread debugging using libthread_db enabled]
[New Thread -1208084800 (LWP 32021)]
[New Thread -1207960656 (LWP 32024)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1207960656 (LWP 32024)]
0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
(gdb) bt
#0 0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
#1 0x008d1deb in vfprintf () from /lib/tls/libc.so.6
#2 0x008da40f in fprintf () from /lib/tls/libc.so.6
#3 0x080485b0 in func (ptr=0x0) at fprintf_thread_clean.c:28
#4 0x00ade341 in start_thread () from /lib/tls/libpthread.so.0
#5 0x0095efee in clone () from /lib/tls/libc.so.6

************************************************** *******************************
If i change stderr to stdout. the fprintf does not dump core.
OS used : Linux 2.6.9-11.ELsmp

Please help me.

Thanks in advance
Vamsi
Aug 18 '08 #1
3 3775
On 18 Aug, 11:02, vamsi <vamsi.kom...@gmail.comwrote:
I have a program, where involves creation of a thread with stack size
of 16k(minimum stack size).
and at that point you left the realm of standard C.
Standard C has no threads or stacks. Uou nedd to try
a Unix(?) group.

There is an fprintf statement in the
created thread code.
I see that there is a core dump occuring at fprintf.

code snippet :
************************************************** ********************************
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
void func(void *);

#define OUTSTREAM stderr

pthread_attr_t attr;
main()
{
* * * * pthread_t p[10];
* * * * void *exitstatus;
* * * * int i;
* * * * pthread_attr_init(&attr);
* * * * if(pthread_attr_setstacksize (&attr,16ul * 1024ul))
* * * * {
* * * * * * * * printf("\n\n\nfailed to set stack size");
* * * * }
* * * * pthread_create(&p[i],&attr,func,NULL);
what is i at this point? is &p[i] a valid location?
>
* * * * sleep(1000);

}

void func(void *ptr)
{
* * * * int i ;
* * * * char str[100];
* * * * fprintf(OUTSTREAM," FIRST :: Thread Created and here is fprintf
\n");

}

core dump trace in gdb:
Starting program: /users/a21313/fprintf/ftest_clean
[Thread debugging using libthread_db enabled]
[New Thread -1208084800 (LWP 32021)]
[New Thread -1207960656 (LWP 32024)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1207960656 (LWP 32024)]
0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
(gdb) bt
#0 *0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
#1 *0x008d1deb in vfprintf () from /lib/tls/libc.so.6
#2 *0x008da40f in fprintf () from /lib/tls/libc.so.6
#3 *0x080485b0 in func (ptr=0x0) at fprintf_thread_clean.c:28
#4 *0x00ade341 in start_thread () from /lib/tls/libpthread.so.0
#5 *0x0095efee in clone () from /lib/tls/libc.so.6

************************************************** ********************************
If i change stderr to stdout. the fprintf does not dump core.
OS used : Linux 2.6.9-11.ELsmp

--
Nick Keighley
Aug 18 '08 #2
On Aug 18, 3:11 pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 18 Aug, 11:02, vamsi <vamsi.kom...@gmail.comwrote:
I have a program, where involves creation of a thread with stack size
of 16k(minimum stack size).

and at that point you left the realm of standard C.
Standard C has no threads or stacks. Uou nedd to try
a Unix(?) group.
There is an fprintf statement in the
created thread code.
I see that there is a core dump occuring at fprintf.
code snippet :
************************************************** ********************************
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
void func(void *);
#define OUTSTREAM stderr
pthread_attr_t attr;
main()
{
pthread_t p[10];
void *exitstatus;
int i;
pthread_attr_init(&attr);
if(pthread_attr_setstacksize (&attr,16ul * 1024ul))
{
printf("\n\n\nfailed to set stack size");
}
pthread_create(&p[i],&attr,func,NULL);

what is i at this point? is &p[i] a valid location?


sleep(1000);
}
void func(void *ptr)
{
int i ;
char str[100];
fprintf(OUTSTREAM," FIRST :: Thread Created and here is fprintf
\n");
}
core dump trace in gdb:
Starting program: /users/a21313/fprintf/ftest_clean
[Thread debugging using libthread_db enabled]
[New Thread -1208084800 (LWP 32021)]
[New Thread -1207960656 (LWP 32024)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1207960656 (LWP 32024)]
0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
(gdb) bt
#0 0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
#1 0x008d1deb in vfprintf () from /lib/tls/libc.so.6
#2 0x008da40f in fprintf () from /lib/tls/libc.so.6
#3 0x080485b0 in func (ptr=0x0) at fprintf_thread_clean.c:28
#4 0x00ade341 in start_thread () from /lib/tls/libpthread.so.0
#5 0x0095efee in clone () from /lib/tls/libc.so.6
************************************************** ********************************
If i change stderr to stdout. the fprintf does not dump core.
OS used : Linux 2.6.9-11.ELsmp

--
Nick Keighley
i=0; even then it dumps core. I shall try posting in other groups as
well.
Aug 18 '08 #3
In article <6b**********************************@v1g2000pra.g ooglegroups.com>,
vamsi <va**********@gmail.comwrote:
if(pthread_attr_setstacksize (&attr,16ul * 1024ul))
An obvious possibility is that this stack size is too small. Have
you tried other sizes, or using the default size?

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Aug 18 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andrew Fabbro | last post by:
I have code with stuff like this all over it: sprintf(errmsg,"somefunc(): %s has illegal character %c",somestring,somechar); fatal_error(errmsg); where fatal_error() just fprintf's to stderr...
7
by: jchludzinski | last post by:
I tryin' to print out a string with a variable number of blanks/spaces preceding the string. I know that if I use: fprintf( stdout, "%12s", string ); I get 12 blanks preceding 'string'. If I...
6
by: QQ | last post by:
In C and SQL I write a very simple program and it works However when I try to create a MYSQL object and call it in the function, it fails. Here is my program, what's wrong? Thanks a lot! ...
1
by: QQ | last post by:
hello I need to listen to two ports and process the received message. Which way to do is better? I have a short program like this but I am not sure whether it is good or not. Or I'd better open...
8
by: AG | last post by:
Hello, This is my first post to this group, and on top of that I am a beginner. So please direct me to another group if this post seems out of place.... I have recently written a program which...
2
by: canteyn | last post by:
Here is my problem, my code is working correctly, and the program is functioning as it should, however I want the person using the program to be able to enter 'y', 'Y', 'n', or 'N' for whether or not...
8
by: sore eyes | last post by:
Hi I just downloaded the free Watcom compiler and am having a little trouble with File IO http://www.openwatcom.org/index.php/Download I downloaded the following example, commented out the...
11
by: David Mathog | last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix write, but no fwrite. That is, no portable C method for writing binary data, only system calls which were OS specific. At...
83
by: Bill Cunningham | last post by:
I have this code I would like to clean up. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { double x, y, a, b; FILE *fp; x = strtod(argv, NULL);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.