(uname -a: Linux srv343.revere.com 2.4.20-30.9 #1 Wed Feb 4 20:44:26
EST 2004 i686 i686 i386 GNU/Linux)
I'm pulling my hair out over here...
I have a program that forks off a child, and uses wait3 to (1) wait
for the child to finish, and to (2) collect and report system usage
info.
Now, in the process of narrowing stuff down, I've come to the
following two lines of code that illustrate the problem:
wait3(&status,0,usage);
printf("...hi...\n\n");
printf(">>> %f \n\n", 67.8);
In theory, the 2nd line should simply print out the number
67.800000... Nothing programmatic or complex going on. However, when
I compile (which gives no errors/warnings) and run, I get this output:
hi....
Segmentation fault
Now, if I comment out the wait3 line (and make no other change
whatsoever), a compile and run gives me:
hi.... 67.800000
....and things seem to be working ok. Also, if I do:
printf(">>> %d",67)
....I get >>> 67 (valid output), with wait3 and without wait3.
So, can anyone think of a reason why printf would smash like this?
Any help is greatly appreciated... Thanks! 3 1800
"Chris" <ia*******@hotmail.com> wrote in message
news:93**************************@posting.google.c om... (uname -a: Linux srv343.revere.com 2.4.20-30.9 #1 Wed Feb 4 20:44:26 EST 2004 i686 i686 i386 GNU/Linux)
I'm pulling my hair out over here...
I have a program that forks off a child, and uses wait3 to (1) wait for the child to finish, and to (2) collect and report system usage info.
Now, in the process of narrowing stuff down, I've come to the following two lines of code that illustrate the problem:
1) Off topic (but I'll answer your question anyway)
2) Not enough of your code to diagnose the problem
wait3(&status,0,usage); printf("...hi...\n\n"); printf(">>> %f \n\n", 67.8);
In theory, the 2nd line should simply print out the number 67.800000... Nothing programmatic or complex going on. However, when I compile (which gives no errors/warnings) and run, I get this output:
hi.... Segmentation fault
I'm guessing you've either defined "usage" as a pointer to a struct rusage
and assigned no space for it, or you've defined "usage" as a struct rusage
and are passing it (by value) to wait3(). wait3() expects as its third
argument a pointer to a struct rusage. This means you have two possible
options:
int status;
struct rusage *usage;
usage=malloc(sizeof *usage);
wait3(&status,0,usage);
free(usage);
or:
int status;
struct rusage usage;
wait3(&status,0,&usage);
Now, if I comment out the wait3 line (and make no other change whatsoever), a compile and run gives me:
hi.... >>> 67.800000 ...and things seem to be working ok. Also, if I do:
printf(">>> %d",67)
...I get >>> 67 (valid output), with wait3 and without wait3.
You have obfuscated the matter, printf has nothing to do with it.
So, can anyone think of a reason why printf would smash like this?
Any help is greatly appreciated... Thanks!
Ah... Yep, you were right. It's the night bearing down on me.
And I agree, this was OT. Shoulda been in comp.unix.programmer. Thanks for
the help, just the same!
"Kieran Simkin" <ki****@digital-crocus.com> wrote in message
news:sAdwc.7$XX2.6@newsfe4-gui... "Chris" <ia*******@hotmail.com> wrote in message news:93**************************@posting.google.c om... (uname -a: Linux srv343.revere.com 2.4.20-30.9 #1 Wed Feb 4 20:44:26 EST 2004 i686 i686 i386 GNU/Linux)
I'm pulling my hair out over here...
I have a program that forks off a child, and uses wait3 to (1) wait for the child to finish, and to (2) collect and report system usage info.
Now, in the process of narrowing stuff down, I've come to the following two lines of code that illustrate the problem:
1) Off topic (but I'll answer your question anyway) 2) Not enough of your code to diagnose the problem
wait3(&status,0,usage); printf("...hi...\n\n"); printf(">>> %f \n\n", 67.8);
In theory, the 2nd line should simply print out the number 67.800000... Nothing programmatic or complex going on. However, when I compile (which gives no errors/warnings) and run, I get this output:
hi.... Segmentation fault
I'm guessing you've either defined "usage" as a pointer to a struct rusage and assigned no space for it, or you've defined "usage" as a struct rusage and are passing it (by value) to wait3(). wait3() expects as its third argument a pointer to a struct rusage. This means you have two possible options:
int status; struct rusage *usage; usage=malloc(sizeof *usage); wait3(&status,0,usage); free(usage);
or:
int status; struct rusage usage; wait3(&status,0,&usage);
Now, if I comment out the wait3 line (and make no other change whatsoever), a compile and run gives me:
hi.... >>> 67.800000
...and things seem to be working ok. Also, if I do:
printf(">>> %d",67)
...I get >>> 67 (valid output), with wait3 and without wait3.
You have obfuscated the matter, printf has nothing to do with it.
So, can anyone think of a reason why printf would smash like this?
Any help is greatly appreciated... Thanks!
In <sAdwc.7$XX2.6@newsfe4-gui> "Kieran Simkin" <ki****@digital-crocus.com> writes: "Chris" <ia*******@hotmail.com> wrote in message news:93**************************@posting.google. com... (uname -a: Linux srv343.revere.com 2.4.20-30.9 #1 Wed Feb 4 20:44:26 EST 2004 i686 i686 i386 GNU/Linux)
I'm pulling my hair out over here...
I have a program that forks off a child, and uses wait3 to (1) wait for the child to finish, and to (2) collect and report system usage info.
Now, in the process of narrowing stuff down, I've come to the following two lines of code that illustrate the problem: 1) Off topic (but I'll answer your question anyway)
Not really. Imagine that wait3 was spelled as foo.
2) Not enough of your code to diagnose the problem
That's true. But enough code for an educated guess, even for the
non-Unix programmer who has no clue about what wait3 might be: this
function was incorrectly called, by someone fool enough not to use the
full diagnosing capabilities of his compiler. wait3(&status,0,usage); printf("...hi...\n\n"); printf(">>> %f \n\n", 67.8);
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: |
last post by:
void show( char *s, ...) is a function seemd like prinf
code
--------------
#include <stdio.h>
#include <stdarg.h>
void show( char *s, ...)
{
va_list stage;
|
by: Evie |
last post by:
I understand that when a switch statement is used without breaks, the
code continues executing even after a matching case is found. Why,
though, are subsequent cases not evaluated?
I wrote a...
|
by: fieldfallow |
last post by:
Hello all,
Before stating my question, I should mention that I'm fairly new to C.
Now, I attempted a small demo that prints out the values of C's numeric
types, both uninitialised and after...
|
by: quarkLore |
last post by:
Following program is erroneous as I am passing a float as int. The
output is
---
|
V
Int f is 0 float f is 0.000000
float f is 3.000000 int f is 0
|
by: Sanjay Kulkarni |
last post by:
I am facing some problems while trying to explore the printf
statement:
Expected Actual
Result Statement Result
1 printf("x = %d", 18.0 / 14); 18725
5.0 printf("\nx = %f",...
|
by: alice |
last post by:
Can someone tell me why, in IE7, the spaces in the footer (C 2007
ESSENCE) become line breaks on this this page http://s195679515.onlinehome.us/essence/index.html
?
|
by: Itaichuk |
last post by:
Hi
I read in several CSS tutorials that block-level elements, such as
<div& <pare rendered with an implicit line break before and
after.
I set to test this out using the following HTML:
I...
|
by: Ouroborus777 |
last post by:
I've been messing around with printing floats. It seems that printf()
is only capable of printing the fractional portion at a fixed length.
Is there some way to print floats such that the full...
|
by: =?ISO-8859-15?Q?L=E9na=EFc?= Huard |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello all,
For some reasons, somewhere in a program, I'd like, if possible, to quickly
parse a whole file before rewinding it and letting the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |