Python取证 - 多处理支持

法医专家通常发现很难应用数字解决方案来分析常见犯罪中的大量数字证据.大多数数字调查工具都是单线程的,它们一次只能执行一个命令.

在本章中,我们将重点介绍Python的多处理功能,它可以与常见的取证相关.挑战.

多处理

多处理定义为计算机系统支持多个进程的能力.支持多处理的操作系统允许多个程序同时运行.

有多种类型的多处理,例如对称非对称处理 .下图是指对称多处理系统,通常在法医调查中遵循.

Multiprocessing

示例

以下代码显示了Python编程内部如何列出不同的进程.

import random
import multiprocessing

def list_append(count, id, out_list): 
   #appends the count of number of processes which takes place at a time
   for i in range(count):
      out_list.append(random.random())
         
   if __name__ == "__main__": 
      size = 999  
      procs = 2
      # Create a list of jobs and then iterate through 
      # the number of processes appending each process to 
      # the job list  
      jobs = []
         
   for i in range(0, procs): 
      out_list = list() #list of processes 
      process1 = multiprocessing.Process(
         target = list_append, args = (size, i, out_list))

      # appends the list of processes
      jobs.append(process)

   # Calculate the random number of processes
   for j in jobs:
      j.start()  #initiate the process

   # After the processes have finished execution
   for j in jobs:
      j.join()
      print "List processing complete."

这里,函数 list_append()有助于列出系统中的进程集.

输出

我们的代码将产生以下输出 :

多处理支持输出