Sponsored Content
Top Forums Programming Question on order of headers and WEXITSTATUS Post 302120189 by frequency8 on Monday 4th of June 2007 10:51:20 PM
Old 06-04-2007
Question on order of headers and WEXITSTATUS

In one of the Unix Programming FAQ's they have the following headers in the program to catch SIGCHLD

Code:
#include <sys/types.h>  /* include this before any other sys headers */
#include <sys/wait.h>   /* header for waitpid() and various macros */
#include <signal.h>     /* header for signal functions */
#include <stdio.h>      /* header for fprintf() */
#include <unistd.h>     /* header for fork() */

Why does <sys/types.h> have to be placed before any other sys headers in this case?

And the second question. In the following code snippet, when I have status>>8 on a sep. line, I get an exit status of 256 when no one is logged on.

Code:
if (status != 0) {
    fprintf(stderr, "No one logged on.\n");
    WEXITSTATUS(status);
    status>>8;
    printf("%d\n", status);
    exit(EXIT_FAILURE);
    }


However, when I put status>>8 in printf() like in the following
Code:
if (status != 0) {
    fprintf(stderr, "No one logged on.\n");
    WEXITSTATUS(status);
    printf("%d\n", status>>8);
    exit(EXIT_FAILURE);
    }

I get an exit status of 1 when no one is logged on. I don't understand how the placement of status>>8 has an impact on the exit code.
 

10 More Discussions You Might Find Interesting

1. Programming

C Headers

Where can i get C/C++ headers for OS MINIX 2.0.3? (0 Replies)
Discussion started by: biosdos
0 Replies

2. Shell Programming and Scripting

Remove text between headers while leaving headers intact

Hi, I'm trying to strip all lines between two headers in a file: ### BEGIN ### Text to remove, contains all kinds of characters ... Antispyware-Downloadserver.com (Germany)=http://www.antispyware-downloadserver.c om/updates/ Antispyware-Downloadserver.com #2... (3 Replies)
Discussion started by: Trones
3 Replies

3. Shell Programming and Scripting

Merging of files with different headers to make combined headers file

Hi , I have a typical situation. I have 4 files and with different headers (number of headers is varible ). I need to make such a merged file which will have headers combined from all files (comman coluns should appear once only). For example - File 1 H1|H2|H3|H4 11|12|13|14 21|22|23|23... (1 Reply)
Discussion started by: marut_ashu
1 Replies

4. Programming

Byte order question

Hi, The structure that will follow is supposed to hold the following RTP header field 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ... (3 Replies)
Discussion started by: emitrax
3 Replies

5. Programming

C - WEXITSTATUS() question

I want to check if an application is still running under C. So far I've been using int rc; rc=WEXITSTATUS( ) if(rc > 0) { //then I exited } I was wondering seeing as WEXITSTATUS in man pages is close to the WAIT() if it was thread blocking and if it was how would I go about making... (4 Replies)
Discussion started by: james2432
4 Replies

6. UNIX for Dummies Questions & Answers

tcpdump and prism headers question

Hello everyone! I installed OpenWRT on a WRT54G-TM (linux 2.4). No problem so far!. I also installed tcpdump on the box. I set the adapter in monitor mode. wlc monitor 1 It created the prism0 interface. Tcpdumpíng is also possible using this interface. root@cmWRT:/tmp# tcpdump -i... (1 Reply)
Discussion started by: aztroboy
1 Replies

7. Programming

help with WEXITSTATUS in C

when a execute this line printf("%d\n",WEXITSTATUS(status)); i get no output, whats could be the possible causes? ---------- Post updated at 09:29 PM ---------- Previous update was at 09:27 PM ---------- nvm i figured it out, u can delete this thread (0 Replies)
Discussion started by: omega666
0 Replies

8. Shell Programming and Scripting

CSv2dat file headers and columns order

Dear all, I have a csv file which is transformed to .dat. I have an awk file which is supposing to do the mapping of the dat file. the code from the awk file is the one below. The content of the dat file is looking like this (tab separated): ODT AGE CDT CO SEX TIME ... (9 Replies)
Discussion started by: grikoss
9 Replies

9. Programming

Oracle 11g optimizer best join order question

Hi team Optimizer max permutations and search limit are set to 3.5 million and 10 respectively.The parameter instruct optimizer to evaluate up to 3.5 million permutations for max 10 table joins I have query with 9 tables joined. How many combinations will optimizer perform to find best... (1 Reply)
Discussion started by: Perlbaby
1 Replies

10. Shell Programming and Scripting

awk to compare files and validate order of headers

The below awk verifies the count and order of each text file in the directory. The script does execute and produce output, however the order of the headers are not compared to key. The portion in bold is supposed to do that. If the order of the headers in each text file is the same as key, then... (0 Replies)
Discussion started by: cmccabe
0 Replies
explain_waitpid(3)					     Library Functions Manual						explain_waitpid(3)

NAME
explain_waitpid - explain waitpid(2) errors SYNOPSIS
#include <libexplain/waitpid.h> const char *explain_waitpid(int pid, int *status, int options); const char *explain_errno_waitpid(int errnum, int pid, int *status, int options); void explain_message_waitpid(char *message, int message_size, int pid, int *status, int options); void explain_message_errno_waitpid(char *message, int message_size, int errnum, int pid, int *status, int options); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the waitpid(2) system call. explain_waitpid const char *explain_waitpid(int pid, int *status, int options); The explain_waitpid function is used to obtain an explanation of an error returned by the waitpid(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (waitpid(pid, status, options) < 0) { fprintf(stderr, "%s ", explain_waitpid(pid, status, options)); exit(EXIT_FAILURE); } pid The original pid, exactly as passed to the waitpid(2) system call. status The original status, exactly as passed to the waitpid(2) system call. options The original options, exactly as passed to the waitpid(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_errno_waitpid const char *explain_errno_waitpid(int errnum, int pid, int *status, int options); The explain_errno_waitpid function is used to obtain an explanation of an error returned by the waitpid(2) system call. The least the mes- sage will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (waitpid(pid, status, options) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_waitpid(err, pid, status, options)); exit(EXIT_FAILURE); } errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. pid The original pid, exactly as passed to the waitpid(2) system call. status The original status, exactly as passed to the waitpid(2) system call. options The original options, exactly as passed to the waitpid(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_message_waitpid void explain_message_waitpid(char *message, int message_size, int pid, int *status, int options); The explain_message_waitpid function may be used to obtain an explanation of an error returned by the waitpid(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (waitpid(pid, status, options) < 0) { char message[3000]; explain_message_waitpid(message, sizeof(message), pid, status, options); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. pid The original pid, exactly as passed to the waitpid(2) system call. status The original status, exactly as passed to the waitpid(2) system call. options The original options, exactly as passed to the waitpid(2) system call. explain_message_errno_waitpid void explain_message_errno_waitpid(char *message, int message_size, int errnum, int pid, int *status, int options); The explain_message_errno_waitpid function may be used to obtain an explanation of an error returned by the waitpid(2) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (waitpid(pid, status, options) < 0) { int err = errno; char message[3000]; explain_message_errno_waitpid(message, sizeof(message), err, pid, status, options); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. pid The original pid, exactly as passed to the waitpid(2) system call. status The original status, exactly as passed to the waitpid(2) system call. options The original options, exactly as passed to the waitpid(2) system call. SEE ALSO
waitpid(2) wait for process to change state explain_waitpid_or_die(3) wait for process to change state and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_waitpid(3)
All times are GMT -4. The time now is 01:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy