#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
#include "kernel/param.h"

int
main()
{
  int pid = fork();
  if (pid < 0) {
    printf("[pid %d] Fork failed\n", getpid());
    exit(pid);
  }

  if (pid == 0) {
    while (!pause(2))
      printf("[pid %d] Hello from target\n", getpid());
  } else {
    pause(10);

    if (signal(pid, SIGSTOP) == 0)
      printf("[pid %d] Target stopped\n", getpid());
    else {
      printf("[pid %d] Signal failed\n", getpid());
      exit(-1);
    }

    pause(20);

    if (signal(pid, SIGCONT) == 0)
      printf("[pid %d] Target started\n", getpid());
    else {
      printf("[pid %d] Signal failed\n", getpid());
      exit(-1);
    }

    pause(20);

    if (kill(pid) == 0)
      printf("[pid %d] Child killed\n", getpid());
    else {
      printf("[pid %d] Kill failed\n", getpid());
      exit(-1);
    }

    pause(5);

    int ret = wait(0);
    if (ret == pid)
      printf("[pid %d] Kill succeeded\n", getpid());
    else {
      printf("[pid %d] Wait failed\n", getpid());
      exit(ret);
    }
  }

  exit(0);
}
