0

I am new in C programming and was asked to write a simple program with these requirements:

  • creates a separate process to execute the external program, doStuff

  • waits for 10 seconds

  • sends an SIGUSR1 signal to the child process, and

  • obtains and prints the exit status of the child process.

I do not really have the doStuff with me.

I am not sure how to meet the last requirement, should I use waitpid()? I haven't learned it yet. May I know how to apply that to my program as

Here is the code I did, I know is simple so I am not sure did I do it rightly. May anyone can kindly let me know am I doing it on the right direction?

Thank you so much.

#include <stdio.h>
#include <signal.h>
#include "doStuff.h"
// which inculde the funcion "doStuff"

int main()
{
    doStuff();

    sleep(10);

    signal(SIGUSR1, doStuff);


}
Mathieu
  • 8,840
  • 7
  • 32
  • 45
  • 3
    You need to use `fork()`, `exec()`, and `wait()`. – Barmar Jun 19 '17 at 21:06
  • Also look the status returned contains extra data. You should use `wexitstatus`. – Tony Tannous Jun 19 '17 at 21:30
  • 1
    Which of [`fork()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html), [`execv()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/execv.html) and either [`wait()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html) or [`waitpid()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/waitpid.html) is giving problems? What problems? There are a myriad related questions on SO. – Jonathan Leffler Jun 19 '17 at 21:39

0 Answers0