OpenVAS Scanner  7.0.1~git
processes.h File Reference

processes.c header. More...

#include <sys/types.h>
Include dependency graph for processes.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* process_func_t) (void *)
 

Functions

pid_t create_process (process_func_t, void *)
 Create a new process (fork). More...
 
int terminate_process (pid_t)
 Send SIGTERM to the pid process. Try to wait the the process. In case of the process has still not change the state, it sends SIGKILL to the process and must be waited later to avoid leaving a zombie process. More...
 

Detailed Description

processes.c header.

Definition in file processes.h.

Typedef Documentation

◆ process_func_t

typedef void(* process_func_t) (void *)

Definition at line 31 of file processes.h.

Function Documentation

◆ create_process()

pid_t create_process ( process_func_t  ,
void *   
)

Create a new process (fork).

Definition at line 97 of file processes.c.

References init_child_signal_handlers(), and pid.

Referenced by attack_network(), nasl_plugin_launch(), and plugins_init().

98 {
99  int pid;
100 
101  pid = fork ();
102 
103  if (pid == 0)
104  {
106  srand48 (getpid () + getppid () + (long) time (NULL));
107  (*function) (argument);
108  exit (0);
109  }
110  if (pid < 0)
111  g_error ("Error : could not fork ! Error : %s", strerror (errno));
112  return pid;
113 }
static pid_t pid
static void init_child_signal_handlers()
Definition: processes.c:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ terminate_process()

int terminate_process ( pid_t  pid)

Send SIGTERM to the pid process. Try to wait the the process. In case of the process has still not change the state, it sends SIGKILL to the process and must be waited later to avoid leaving a zombie process.

Parameters
[in]pidProcess id to terminate.
Returns
0 on success, -1 if the process was waited but not changed the state

Definition at line 58 of file processes.c.

References pid.

Referenced by pluginlaunch_stop(), and update_running_processes().

59 {
60  int ret;
61 
62  if (pid == 0)
63  return 0;
64 
65  ret = kill (pid, SIGTERM);
66 
67  if (ret == 0)
68  {
69  usleep (1000);
70 
71  if (waitpid (pid, NULL, WNOHANG) >= 0)
72  {
73  kill (pid, SIGKILL);
74  return -1;
75  }
76  }
77 
78  return 0;
79 }
static pid_t pid
Here is the caller graph for this function: