一个循环中反复分叉的程序如何被杀死?

时间:2019-07-18 15:25:58

标签: c kill

我做了一些奇怪的实验,并创建了一个程序,该程序将自身分叉并在子进程中执行,然后将其再次分叉并再次执行。。。依此类推。

仅在退出ssh会话后,我才连接到它。 有什么方法可以杀死此类程序,从而不断更改其自身的PID?

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>


int spawn (char* program, char** arg_list)
{
  pid_t child_pid;


  child_pid = fork ();
  if (child_pid != 0)
    /* This is the parent process. */
    return child_pid;
  else {

    printf("my pid is %d my ppid is %d\n", getpid(), getppid());
    execvp (program,  arg_list);

    fprintf (stderr,  "an error occurred in execvp\n");
    abort ();
  }
}

int main ()
{

  char* arg_list[] = {
    "./1",     /* argv[0], the name of the program.  */
    NULL      
  };

  spawn ("./1", arg_list);

  return 0;
}

0 个答案:

没有答案