c - Concurrent Processes -


I'm looking to run several concurrent processes in one program. The program will take the argument from the user and then execute each argument as a child procedure. I think that this means that what I have to do, it ensures that every time the thorn () is done by the original parent process, and then the result of the hair process goes on at the same time, and gradually No.

Am I right to think this? And can someone tell me how can I go about doing this?

Forgive me to delete my last reply (as suggested by using threads ) In the case of the hand, because I'm going completely new direction, I feel compelled to add it as a separate answer.

Short version:

Please make the following changes to your program:

  1 length = argc ; // Size of length = sizeof (argv); 2. execl (argv [i], argv [i], 0); // in place of execvp (argv [i], 0); 3. Add & lt; Unistd.h & gt; // If you already have  

long version:

(1) variable Length , I think you want to get the total number of arguments. argv is a pointer-to-four-pointer , and as is the only memory address if you print the length of your program, you will see that it is always 4 (or whatever is the size of the memory address in your system).

Then it:

  length = size (argv);  

In fact it should be:

  length = argc;  

argc contains the total number of arguments passed when executing the process, for example,

  ./a / bin / Ps / bin / ls  

gives: argc = 3 ( (2) another issue with your program Execvp does not call 2 .

The prototype for execvp is as follows:

  int execvp (const char * file, char * Const argv []);  

Where, argv is the list of arguments passed to the new order, which is very similar to your own program

What do you use in your program:

  execvp (argv [i], 0);  

Assume that i = 1 and argv [1] = "/ bin / ls" . What does this command do / bin / ls execution Passable & Pass a null pointer ( 0 ) to do this, this can cause a runtime error:

  A NULL argv [0] An ADC system The call was passed through.  

The mention of the ADM man page is,

The first argument, by convention, should be indicated on the file name associated with the file being executed.

Although it is not compulsory to return the file name again, you certainly should not pass a zero indicator because you do not want to pass any argument, so I recommend That you use the following execl call, instead:

  execl (argv [i], argv [i], 0);  

Remember that all these calls are ultimately by execve () end & amp; Then executed, at the end of making them equal

I will give you the man .

. I encourage you to read more about the family of tasks.

Comments