How to use execl() to execute another program

10k views Asked by At

I have an assignment on producer-consumer with using multiprocessor and shared memory

I have a question how to use execl() to execute another file

In my program will consist of 3 c files

parent.c : parent process

producer.c : producer process

consumer.c : consumer process

After I compile the file -> name parent,producer,consumer

If I put directory that I put all the files are : /home/assign

in parent.c I have a code to call producer and consumer by fork like this

if (fork() == 0) {  /* in producer process */
      /* Replace this program with producer program */

      /*idea : execl => path of execution of the program*/

      if (execl("/home/assign", "producer", NULL) == -1) {
         perror("execl failed for producer");
         cleanup_on_exit();   /* clean up before exiting */
         exit(3);
         }
       }

if (fork() == 0) {  /* in consumer process */
      /* Replace this program with the consumer program */
      if (execl("/home/assign", "consumer", NULL) == -1) {
         perror("execl failed for consumer");
         cleanup_on_exit();  /* clean up before exiting */
         exit(3);
         }
      }

wait(NULL);
wait(NULL);

however when I run the program through Linux command ./parent

It show result like this

execl failed for producer
execl failed for consumer

which I know that something wrong between path or the execution command

Can you help with this

1

There are 1 answers

0
Armali On

if (execl("/home/assign/producer", "producer", NULL) == -1) {, and similar for consumer. – wildplasser