Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 225 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Meaning of wait((int *)0)

#1
One such program that uses a wait function like this is this one:

#include<stdio.h>
#include<stdlib.h>
int main()
{
int pid,fd[2]; int n; char line[20];
if(pipe(fd)<0) {
printf("Error creating pipe");
} else {
pid=fork();
if(pid<0) {
printf("Error while forking");
} else {
if(pid>0) {
close(fd[0]);
write(fd[1],"Hello\n",6);
while(wait((int *)0)!=pid);
} else {
close(fd[1]);
n=read(fd[0],line,20);
if(n<0)
printf("Error reading a file");
write(1,line,n);
}
}
}
return 0;
}
Reply

#2
See [man wait(2)](

[To see links please register here]

).

`wait((int *)0)` calls `waitpid(-1, (int *)0, 0)`. The man page states:

>If status is not NULL, wait() and waitpid() store status information in the int to which it points.

Here, `status` is NULL (0). Thus, your call to `wait` waits for a state change in any child process, and does not return a status. The call merely checks to see if a state change occurred for a specific child process (`pid` in your case).
Reply

#3
stager's answer is correct. Though it should be noted that the cast is entirely unnecessary since according to the standard, 0 used in a pointer context is the NULL pointer.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through