Program a creates child processes and invokes process B, depending on the different cases that are not called, and the results are displayed differently.
#include <stdio.h>#include<unistd.h>#include<sys/wait.h>#include<sys/types.h>#include<errno.h>intMain () {pid_t pid, rpid; intStat; if(PID = fork ()) <0) {perror ("Fork Failue."); } printf ("pid =%d\n", PID);//The obtained return value of the print child parent process if(PID = =0) { intx = Execl ("./test123","./test", NULL); printf ("x =%d\n", x);//Execl call failed return-1Perror ("execl Failue");//output the error string directly using the Perror function (the string is easier to understand than a number)printf"%s\n", Strerror (errno));//indirect use of strerror output error string}Else{rpid= Waitpid (-1, &stat,0);//wait for any child process to end if(wifexited (STAT)) {//The status word has 24 bits, and some macro functions explain the status wordprintf"Rpid =%d, stat =%d\n", Rpid, Wexitstatus (stat)); } } return 0;}
Program A
#include <stdio.h>int main (intChar * *argv) { printf (" Hello world.\n"); Exit (0x3244// return and exit will return normally, return value int & 0xFF}
Program B
After the call succeeds:
[Email protected]:~/projects/webserver$./ptest
PID = 4723
PID = 0
Hello world.
Rpid = 4723, stat = 68
After the call fails:
[Email protected]:~/projects/webserver$./ptest
PID = 4738
PID = 0
x =-1
Execl failue:no such file or directory
No such file or directory
Rpid = 4738, stat = 0
Ps:error code meaning, from the network Http://hi.baidu.com/henfengduandie/item/7c06bdb8e3a617f362388eb6
errno.00 is:success Success
errno.01 is:operation not permitted does not allow this type of operation
errno.02 is:no Such file or directory does not have this
errno.03 Is:no Such process does not have this progress
errno.04 is:interrupted System Call Interrupt
errno.05 is:input/output error input and output errors
errno.06 Is:no Such device or address does not have it
errno.07 is:argument list too long parameter
errno.08 is:exec Format Error execution
errno.09 Is:bad file descriptor Invalid filename descriptor
errno.10 Is:no Child Processes No sub-processes exist
errno.11 Is:resource temporarily unavailable resource is temporarily unavailable
errno.12 Is:cannot Allocate memory allocation failed
errno.13 is:permission denied permissions error
errno.14 Is:bad Address Error
errno.15 Is:block Device required block devices request
errno.16 Is:device or resource busy device or resource busy
errno.17 Is:file exists file already exists
errno.18 is:invalid Cross-device Link Invalid cross-connect device
errno.19 Is:no Such device does not have this equipment
errno.20 Is:not A directory is not a catalog
errno.21 Is:is A directory is a catalog
errno.22 is:invalid argument parameter is illegal
errno.23 Is:too Many open files in system file too many
errno.24 Is:too Many open files too many file opened
errno.25 is:inappropriate IOCTL for device unit supports this operation
errno.26 is:text file busy text files are busy
errno.27 Is:file too large file is too large
errno.28 Is:no space left on device device has no room, typically a storage device
errno.29 Is:illegal seek illegal seek operation
errno.30 is:read-only File System read-only filesystem
errno.31 Is:too Many links too many connections
errno.32 Is:broken Pipe Rupture
errno.33 is:numerical argument out of domain numeric parameters beyond the range of values
errno.34 is:numerical result out of range value results out of range
errno.35 Is:resource Deadlock avoided resource deadlock
errno.36 is:file name too long filename
errno.37 Is:no locks available No locks available
errno.38 Is:function not implemented function did not execute
errno.39 is:directory not empty directory non-null
errno.40 Is:too Many levels of symbolic links too multi-level symbolic connection
errno.41 Is:unknown Error 41 41 Unknown errors
errno.42 is:no Message type of desired type not accepted
errno.43 Is:identifier removed identifier has been deleted
errno.44 Is:channel number out of range ...
errno.45 Is:level 2 not synchronized
errno.46 Is:level 3 halted
errno.47 Is:level 3 Reset
errno.48 Is:link number out of range
errno.49 Is:protocol Driver not attached
errno.50 IS:NO CSI structure available
errno.51 Is:level 2 halted
errno.52 Is:invalid Exchange
errno.53 Is:invalid Request Descriptor
errno.54 Is:exchange Full
errno.55 Is:no Anode
errno.56 Is:invalid Request Code
errno.57 Is:invalid Slot
errno.58 Is:unknown Error 58
errno.59 Is:bad font file format
errno.60 Is:device not a stream
errno.61 Is:no data available
errno.62 Is:timer Expired
errno.63 Is:out of Streams resources
errno.64 Is:machine isn't on the network
errno.65 Is:package not installed
errno.66 Is:object is remote
errno.67 Is:link has been severed
errno.68 is:advertise Error
errno.69 Is:srmount Error
errno.70 is:communication error on send
errno.71 Is:protocol Error
errno.72 Is:multihop attempted
errno.73 Is:rfs Specific error
errno.74 Is:bad Message
errno.75 Is:value too large for defined data type
errno.76 is:name not unique on network
errno.77 Is:file descriptor in Bad state
errno.78 Is:remote Address changed
errno.79 Is:can not access a needed shared library
errno.80 is:accessing a corrupted shared library
errno.81 is:. lib secion in a.out corrupted
errno.82 is:attempting to link in too many GKFX libraries
errno.83 Is:cannot exec a shared library directly
errno.84 is:invalid or incomplete multibyte or wide character
errno.85 is:interrupted system call should be restarted
errno.86 Is:streams Pipe Error
errno.87 Is:too Many users
errno.88 Is:socket operation on Non-socket
errno.89 Is:destination Address Required
errno.90 Is:message too long
errno.91 is:protocol wrong type for socket
errno.92 Is:protocol Not available
errno.93 Is:protocol not supported
errno.94 Is:socket type not supported
errno.95 Is:operation not supported
errno.96 Is:protocol Family not supported
errno.97 Is:address Family not supported by protocol
errno.98 is:address already in use
errno.99 Is:cannot Assign requested address
Errno.100 Is:network is down
Errno.101 Is:network is unreachable
errno.102 Is:network dropped connection on reset
errno.103 Is:software caused connection abort
errno.104 is:connection Reset by peer
errno.105 Is:no Buffer Space available
errno.106 Is:transport endpoint is already connected
errno.107 Is:transport endpoint is not connected
errno.108 Is:cannot send after transport endpoint shutdown
errno.109 Is:too Many References:cannot splice
errno.110 Is:connection timed out
errno.111 Is:connection refused
errno.112 Is:host is down
errno.113 Is:no route to host
errno.114 Is:operation already in progress
errno.115 Is:operation now in progress
errno.116 is:stale NFS File handle
errno.117 Is:structure Needs cleaning
errno.118 is:not a xenix named type file
errno.119 is:no Xenix semaphores available
errno.120 Is:is a named type file
errno.121 is:remote I/O error
errno.122 Is:disk Quota exceeded
Errno.123 Is:no Medium found
errno.124 Is:wrong Medium Type
errno.125 Is:operation Canceled
errno.126 is:required Key Not available
errno.127 Is:key has expired
errno.128 Is:key has been revoked
errno.129 Is:key was rejected by service
errno.130 Is:owner died
errno.131 Is:state Not recoverable
errno.132 Is:unknown Error 132
132-255 is all unknown error