473,718 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<pthrea d.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_in it(&attr);
if(pthread_attr _setstacksize (&attr,16ul * 1024ul))
{
printf("\n\n\nf ailed to set stack size");
}
pthread_create( &p[i],&attr,func,NUL L);

sleep(1000);

}
void func(void *ptr)
{
int i ;
char str[100];
fprintf(OUTSTRE AM," 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_vfprin tf () from /lib/tls/libc.so.6
(gdb) bt
#0 0x008d1b06 in buffered_vfprin tf () 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 3797
On 18 Aug, 11:02, vamsi <vamsi.kom...@g mail.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<pthrea d.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_in it(&attr);
* * * * if(pthread_attr _setstacksize (&attr,16ul * 1024ul))
* * * * {
* * * * * * * * printf("\n\n\nf ailed to set stack size");
* * * * }
* * * * pthread_create( &p[i],&attr,func,NUL L);
what is i at this point? is &p[i] a valid location?
>
* * * * sleep(1000);

}

void func(void *ptr)
{
* * * * int i ;
* * * * char str[100];
* * * * fprintf(OUTSTRE AM," 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_vfprin tf () from /lib/tls/libc.so.6
(gdb) bt
#0 *0x008d1b06 in buffered_vfprin tf () 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...@g mail.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<pthrea d.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_in it(&attr);
if(pthread_attr _setstacksize (&attr,16ul * 1024ul))
{
printf("\n\n\nf ailed to set stack size");
}
pthread_create( &p[i],&attr,func,NUL L);

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


sleep(1000);
}
void func(void *ptr)
{
int i ;
char str[100];
fprintf(OUTSTRE AM," 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_vfprin tf () from /lib/tls/libc.so.6
(gdb) bt
#0 0x008d1b06 in buffered_vfprin tf () 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************ *************** *******@v1g2000 pra.googlegroup s.com>,
vamsi <va**********@g mail.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
3162
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 and exits. I'd like to change the above to something like: fatal_error("somefunc(): %s has illegal character
7
1415
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 use: n = 12; fprintf( stdout, "%(n)s: ", string );
6
1217
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! #include <stdlib.h> #include <stdio.h> #include "mysql.h" int main(int argc, char *argv) { MYSQL my_connection;
1
1316
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 two threads and process the message seperately. Thanks a lot! #include <stdio.h> #include <stdlib.h>
8
2324
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 calculates loan amortization schedules, writes the data to a text file, and then upon user prompt, the program will display the created file and print the file. Until this morning, everything worked fine, and then I started messing around with...
2
1590
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 the buyer is a teacher, currently I have it setup to where the only way it works is with the lowercase 'y' and 'n' .... could someone please check my code below and tell me what I need to add to have this work with the uppercase letters as well. ...
8
2031
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 Command line arguments so that I could debug more easily. The example is a simple file copy. and it works. but I would like to customize this to automate some redundant changes in some large files.
11
4302
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 C89 fwrite/fread were added to the C standard to allow portable binary IO to files. I wonder though why the choice was made to extend the unix function write() into a standard C function rather than to extend the existing standard C function...
83
2820
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
8827
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8724
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9121
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9053
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4743
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.