Process
An object that represents a subprocess of the current process.
表示当前进程的子进程的对象
class Process : NSObject
Overview
Using the Process class, your program can run another program as a subprocess and can monitor that program’s execution. A Process object creates a separate executable entity; it’s different from Thread
because it doesn’t share memory space with the process that creates it.
使用Process类,你的程序可以将另一个程序作为子进程运行,并可以监视该程序的执行。
Process 对象创建一个单独的可执行的实体;它与 Thread 不同,因为它不需要和创建它的进程共享内存空间
A process operates within an environment defined by the current values for several items: the current directory, standard input, standard output, standard error, and the values of any environment variables. By default, a
Process
object inherits its environment from the process that launches it. If there are any values that should be different for the process (for example, if the current directory needs to change), change the value before your app launches it. Your app can’t change a process’s environment while it’s running.
进程在当前目录、标准输入、标准输出、标准错误和任意环境变量的值等多个项目中运行。
默认情况下,Process 对象从启动它的进程继承其环境。如果进程中存在不同的值(例如,如果需要更改当前目录), 请在启动应用程序之前更改该值。程序无法在运行中更改进程的环境。
You can only run a Process object once. Subsequent attempts raise an error.
Process 对象只能运行一次,以后再尝试会引发错误.
image.pngTopics
Creating and Initializing a Process Object (创建和初始化进程对象)
class func run(URL, arguments: [String], terminationHandler: ((Process) -> Void)?) -> Process
// Creates and runs a task with a specified executable and arguments.
// 使用指定的可执行文件和参数创建并运行任务
init()
// Returns an initialized process object with the environment of the current process.
// 返回具有当前进程环境的初始化进程对象
Returning Process Information (返回进程信息)
var processIdentifier: Int32
// The receiver’s process identifier.
// 接受方的进程ID
Running and Stopping a Process (运行和停止进程)
func run()
// Runs the process with the current environment.
// 在当前环境中运行进程
func interrupt()
// Sends an interrupt signal to the receiver and all of its subtasks.
// 向接收器及其所有子任务发送中断信号
func resume() -> Bool
// Resumes execution of a suspended task.
// 恢复执行暂停的任务
func suspend() -> Bool
// Suspends execution of the receiver task.
// 暂停执行接收器的任务
func terminate()
// Sends a terminate signal to the receiver and all of its subtasks.
// 向接收器及其所有子任务发送终止信号
func waitUntilExit()
// Blocks the process until the receiver is finished.
// 阻塞进程直到接收器完成
Querying the Process State (查询进程状态)
var isRunning: Bool
// A status that indicates whether the receiver is still running.
// 指示接收器是否仍在运行的状态
var terminationStatus: Int32
// The exit status the receiver’s executable returns.
// 接收器可执行文件返回的终止状态
var terminationReason: Process.TerminationReason
// The reason the system terminated the task.
// 系统终止任务的原因
Configuring a Process Object (配置进程对象)
var arguments: [String]?
// The command arguments that the system uses to launch the executable.
// 系统用于启动可执行文件的命令参数
var currentDirectoryURL: URL?
// The current directory for the receiver.
// 接收器的当前目录
var environment: [String : String]?
// The environment for the receiver.
// 接收器的环境
var executableURL: URL?
// The receiver’s executable.
// 接收器的可执行文件
var qualityOfService: QualityOfService
// The default quality of service level the system applies to operations the task executes.
// 系统应用于任务执行的操作的默认 Quality of Service 级别
var standardError: Any?
// The standard error for the receiver.
var standardInput: Any?
// The standard input for the receiver.
var standardOutput: Any?
// The standard output for the receiver.
Process Termination Handler (进程终止处理程序)
var terminationHandler: ((Process) -> Void)?
// A completion block the system invokes when the task completes.
// 任务完成后,系统调用的 completion block
Constants (常量)
enum Process.TerminationReason
// Constants that specify the termination reason values that the system returns.
// 指定系统返回的终止原因值的常量
enum QualityOfService
// Constants that indicate the nature and importance of work to the system.
// 表示工作对系统的性质和重要性的常量
Notifications (进程终止处理程序)
class let didTerminateNotification: NSNotification.Name
// Posted when the task has stopped execution.
// 在任务停止执行时发出的通知
Deprecated (过期)
class func launchedProcess(launchPath: String, arguments: [String]) -> Process
// Creates and launches a task with a specified executable and arguments.
// 使用指定的可执行文件和参数创建并启动任务
Deprecated 已过期
var currentDirectoryPath: String
// Sets the current directory for the receiver.
// 设置接收器的当前目录
Deprecated 已过期
var launchPath: String?
// Sets the receiver’s executable.
// 设置接收器的可执行文件
Deprecated 已过期
func launch()
// Launches the task represented by the receiver.
// 启动接收器代表的任务
Deprecated 已过期
See Also
Tasks and Pipes (任务和管道)
class Pipe
// A one-way communications channel between related processes.
// 相关进程之间的单向通信通道
网友评论