Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > child exit status query

Reply
Thread Tools

child exit status query

 
 
Mike
Guest
Posts: n/a
 
      01-28-2009
Hi everybody

i'm playing round with more child process code.

this is a program straight from my textbook:

void main(argv, argc)
int argc; char *argv[];
{
int wch, wpar;

if(!fork())
{
printf("child pid %d\n", getpid());
printf("enter child exit status:");
scanf("%d", &wch);
printf("child exiting\n");
_exit(wch);
}
printf("waiting for child to exit\n");
waitpid(-1, &wpar, 0);
printf("child exit status was %d\n", (wpar>>&0xff);
}


i'm confused, because when i run it i get

child pid 9567
enter child exit status:waiting for child to exit

and the program just hangs without giving me a chance to enter an exit
status for the child.

can anyone explain? thanks.

 
Reply With Quote
 
 
 
 
Antoninus Twink
Guest
Posts: n/a
 
      01-28-2009
On 28 Jan 2009 at 23:17, Mike wrote:
> i'm confused, because when i run it i get
>
> child pid 9567
> enter child exit status:waiting for child to exit
>
> and the program just hangs without giving me a chance to enter an exit
> status for the child.


All that's happening is that after the fork(), the child process happens
to be the first to execute: it displays its prompt and blocks at the
scanf() call.

Meanwhile, the parent gets scheduled; it prints its message which gets
appended to your prompt.

You should still be able to enter an exit status - just type one in and
press return!

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      01-28-2009
Mike wrote:
> Hi everybody
>
> i'm playing round with more child process code.
>
> this is a program straight from my textbook:
>
> void main(argv, argc)
> int argc; char *argv[];


I'm starting to think you're taking the ****.

If you are serious, post to comp.unix.programmer. You are learning Unix
system programming, not C.

--
Ian Collins
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-28-2009
Mike <> writes:
> i'm playing round with more child process code.

[...]
> can anyone explain? thanks.


Why do you persist in posting to the wrong newsgroup?

Standard C doesn't support processes. Ask your questions in
comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-28-2009
Mike <> writes:
> i'm playing round with more child process code.
>
> this is a program straight from my textbook:
>
> void main(argv, argc)
> int argc; char *argv[];
> {

[...]

What textbook are you using? The use of the old-style function
definition is excusable if it's a very old book; in that case, you
should get a newer one if at all possible. But the use of void as the
return type of main, though it's a common error, is harder to
understand. The "void" keyword was introduced in the 1989 ANSI C
standard -- the very same document that established the requirement
that main returns int. "void main" has *never* been correct.

(Quibble: an implementation is allowed to accept forms of main other
than the two presented in the standard -- but no implementation is
required to do so, and *all* hosted implementations must support "int
main(void)" and "int main(int argc, char *argv[])".)

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      01-28-2009
Mike wrote:

> Hi everybody
>
> i'm playing round with more child process code.


This is one too many. You're either trolling, or unable to read and
comprehend. Either way, a waste of time.

You know, you hate it, but:

*plonk*




Brian
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      01-29-2009
Keith Thompson wrote:
> Mike <> writes:
>> i'm playing round with more child process code.

> [...]
>> can anyone explain? thanks.

>
> Why do you persist in posting to the wrong newsgroup?
>

Because we've been had old boy. Best of all, old Twinky boy's been had
good a proper!

--
Ian Collins
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      01-29-2009
Mark McIntyre <> writes:

> Mike wrote:
>> Hi everybody
>>
>> i'm playing round with more child process code.
>>
>> this is a program straight from my textbook:
>>
>> void main(argv, argc)
>> int argc; char *argv[];

>
> You need to get a new text-book. This style of C is at least 30 years
> old and has been deprecated (ie obsolete) since the mid eighties.


I don't think it was deprecated then and it certainly was not
obsolete. Portable code had to use this style right up into the early
90s (and maybe even later). Your point is valid: it is an obsolete
style, but a 20-25 year old Unix book would have had to use it.

--
Ben.
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      01-29-2009
Ben Pfaff wrote:
> Keith Thompson <kst-> writes:
>
>> Mike <> writes:
>>> void main(argv, argc)
>>> int argc; char *argv[];
>>> {

>> [...]
>>
>> What textbook are you using? The use of the old-style function
>> definition is excusable if it's a very old book; in that case, you
>> should get a newer one if at all possible. But the use of void as the
>> return type of main, though it's a common error, is harder to
>> understand. [...]

>
> Getting the return type of main wrong is only a nit, compared to
> getting its parameters in the wrong order!


Trolls just ain't what they used to be, are they?

--
Ian Collins
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      01-29-2009
Keith Thompson <kst-> writes:

> Mike <> writes:
>> void main(argv, argc)
>> int argc; char *argv[];
>> {

> [...]
>
> What textbook are you using? The use of the old-style function
> definition is excusable if it's a very old book; in that case, you
> should get a newer one if at all possible. But the use of void as the
> return type of main, though it's a common error, is harder to
> understand. [...]


Getting the return type of main wrong is only a nit, compared to
getting its parameters in the wrong order!
--
"The way I see it, an intelligent person who disagrees with me is
probably the most important person I'll interact with on any given
day."
--Billy Chambless
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Any exit status without explicitely using return /exit Keith Thompson C Programming 10 03-03-2010 12:41 AM
Re: Any exit status without explicitely using return /exit jacob navia C Programming 3 02-24-2010 02:39 PM
In a Perl script 'exit 1' returns exit status 0! kaleem Perl Misc 8 12-14-2006 12:52 AM
Code to Exit Web App and Exit Internet Explorer =?Utf-8?B?U2FuZHk=?= ASP .Net 7 08-05-2005 01:55 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57