LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-21-2004, 10:07 PM   #1
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
union wait problem


Hi all,

I'm trying to code a skeleton daemon process on Red Hat 9, using 14-year-old code snippets based on UNIX 4.3BSD and System V.

I am getting a couple of compile errors in the following function:
Code:
void sig_child() {
              
        int             pid;
        union wait      status;

        while( (pid = wait3( &status, WNOHANG, (struct rusage *) 0 )) > 0 );
}
The errors:

skel2.c:14: storage size of `status' isn't known
skel2.c:16: warning: implicit declaration of function `wait3'

I assume I am omitting some header files, but am unsure which. Here are my includes:

#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stropts.h>

Thanks in advance!
 
Old 12-21-2004, 10:38 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Code:
NAME
       wait3, wait4 - wait for process termination, BSD style

SYNOPSIS
       #define _USE_BSD
       #include <sys/types.h>
       #include <sys/resource.h>
       #include <sys/wait.h>

       pid_t wait3(int *status, int options,
             struct rusage *rusage)
It looks like before you include your header files you need to #define _USE_BSD

And I'm not sure what union wait is. wait3() expects an int * for status.
 
Old 12-22-2004, 09:36 AM   #3
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Original Poster
Rep: Reputation: 30
Hi, thanks for your post.

My man page on wait3 is a bit different:

SYNOPSIS
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>

pid_t wait3(int *status, int options,
struct rusage *rusage);

It doesn't specify #define __USE_BSD

I tried that anyway and it still didn't work. Although, in <sys/wait.h> there is a section that defines a union wait #ifdefined __USE_BSD. Curious.

At any rate, since wait3 is clearly expecting an int* for the first argument, I should be fine if I just declare
Code:
int status;
instead of
Code:
union wait status;
since (at this juncture) I am not concerned with portability. Does that makes sense?

P.S. What's up with all the leading underscore characters? Do they have some special significance by convention, or what?
 
Old 12-22-2004, 09:59 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Yes, I wouold do int status and then pass &status to wait3().

The C standard specifies that any variable/macro name that is all capital letters and begins with any number of leading underscores is reserved for implementation namespace. So gcc knows that it's safe (according to the standard) if it names its macros with leading underscores.

Who knows? Maybe someone wants to use a macro called USE_BSD in their own program There's all sorts of namespace restrictions, but I don't know them all of the top of my head. At any rate, the leading underscores are just to avoid namespace contamination
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenBSD 3.8: read-only root with union /dev Moy Easwaran *BSD 2 11-12-2005 02:41 PM
European Union rejects Software Patents! Komakino Linux - General 1 07-06-2005 02:33 PM
union field length mismatch linux_lover2005 Programming 4 05-22-2005 02:28 PM
mpaa & europe union? annehoog General 1 01-09-2003 11:34 AM
Western Union Web Site Hacked - Credit Card Numbers Stolen! jeremy General 0 09-10-2000 02:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration