While we can read your 2 samples, your question hardly make any sense.
According to the POSIX / Single Unix Specification version 4 2018 Edition, when a process had not explicitly indicated to the system that it wants to ignore the statuses of its child processes:
Status information (exit status code, etc.) shall be generated.
The [exiting] process shall be transformed into a zombie process. ...
The process' lifetime shall end once its parent obtains the process' status information ...
If one or more threads in the parent process of the calling process is blocked in a call to wait(), waitid(), or waitpid() awaiting termination of the process, one (or, if any are calling waitid() with WNOWAIT, possibly more) of these threads shall obtain the [exiting] process' status information ... and become unblocked.
A SIGCHLD shall be sent to the parent process.
Note the last point - the SIGCHLD
is always generated (unless the parent specified to ignore it)!
Update
I tested both of your program fragments, wrapped in a stub that I assume to be plausible. Both run successfully. Here's the 2 full program source code and the terminal output:
Full Sample 1.1:
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
if( pid == 0 ) {
printf("child\n");
printf("%d\n", pid);
}
else {
printf("Parent\n");
printf("%d\n", pid);
wait(NULL);
sleep(10);
}
}
Full Sample 1.2:
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
if( pid == 0 ) {
printf("child\n");
printf("%d\n", pid);
}
else {
printf("Parent\n");
printf("%d\n", pid);
sleep(10);
}
}
//64-bit Mac Mini./
$ make s1 s2 ; ./s1 ; ./s2
make: `s1' is up to date.
make: `s2' is up to date.
Parent
46431
child
0
Parent
46449
child
0
//64-bit Mac Mini./
$