Home > Back-end >  Multi-process concurrent program error, to ask the great god I was wrong in what place
Multi-process concurrent program error, to ask the great god I was wrong in what place

Time:09-19

#include
#include
#include
#include
Typedef void (* signal_handler) (int);
Void signal_handler_fun (int signum) {}
Int main () {
Signal (SIGUSR1, signal_handler_fun);
pid_t pid;
Pid_t pid1;
Pid=fork ();
If (pid<0)
{exit (1); }
Else if (pid==0) {
Printf (" child 1 create! \n");
Pause ();
Execlp ("/bin/ls ", "ls", NULL);
Printf (" child 1 is OK! \n");
}
The else {
Pid1=fork ();
If (pid1 & lt; 0)
{exit (1); }
Else if (pid1==0) {
Printf (" child 2 create! \n");
Execlp ("/bin/ps ", "ps", NULL);
Printf (" child 2 is OK! \n");
The kill (pid, SIGUSR1);
}
The else {
While (wait (NULL).=1) {}
exit(0);
}
}
}
Today in operating system experiment, encountered the problem (the first contact with these things, stumbling), how also not solve, title as follows: write a multi-process concurrent execution procedures, the father into repeat every 3 seconds built two child process, first create to perform the ls command, created after implementation to perform the ps command, and control the ps command before the ls command execution, I this code is wrong, ps will be jammed instruction has been completed, then I search on the Internet and found we were both the child sleep, wake up in sequence in the parent, I tried it on, can indeed, but, I why not the code, I'm the first in the process of sleep, the second process wake up after the completion of the first process, why will fail, is my method is to use a wrong or to understand something profound, hope everybody can point out my problem, thank you.

CodePudding user response:

3 seconds in what place?

CodePudding user response:

Linux?

CodePudding user response:

reference 1/f, double cup with wine reply:
3 seconds in what place?

Don't add, I want to a single failure

CodePudding user response:

reference 1/f, double cup with wine reply:
3 seconds in what place?

This is a single code

CodePudding user response:

refer to the second floor MianHou response:
Linux?

Write a c + + under Linux
  • Related