I encountered a problem when writing the code. Please help me check it out. It is very urgent! Thank you.
Source: Internet
Author: User
I encountered a problem when writing the code. Please help me check it out. It is very urgent! Thank you-general Linux technology-Linux technology and application information. For more information, see below. I installed RedHat Linux 5 on VMware. Now, after writing two sections of code and compiling it, the terminal says there are errors and warnings that cannot be run. Can you help me solve them?
# Include
# Include
# Include
Int wait_flag;
Void stop ();
Main (){
Int pid1, pid2;
Signal (3, stop );
While (pid1 = fork () =-1 );
If (pid1> 0 ){
While (pid2 = fork () =-1 );
If (pid2> 0 ){
Wait_flag = 1;
Sleep (5 );
Kill (pid1, 16 );
Kill (pid2, 17 );
Wait (0 );
Wait (0 );
Printf ("\ n Parent process is killed !! \ N ");
Exit (0 );
}
Else {
Wait_flag = 1;
Signal (17, stop );
Printf ("\ n child process 2 is killed by parent !! \ N ");
// Output "child process 2 is killed by parent !!"
Exit (0 );
}
}
Else {
Wait_flag = 1;
Signal (16, stop );
Printf ("\ n child process 1 is killed by parent !! \ N ");
Exit (0 );
}
}
Void stop (){
Wait_flag = 0;
}
After this code is compiled and run, the terminal jumps out of the warning: In the function "main", the implicit declaration is not compatible with the built-in function "exit.
I don't know how to change it. Please take a look! Thank you!
My compilation code is like this: "gcc jincheng. c-o jincheng"
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.