zoukankan      html  css  js  c++  java
  • NStask

    @interface NSTask : NSObject

    // Create an NSTask which can be run at a later time
    // An NSTask can only be run once. Subsequent attempts to
    // run an NSTask will raise.
    // Upon task death a notification will be sent
    // { Name = NSTaskDidTerminateNotification; object = task; }
    //

    //返回当前进程环境下初始化的NStask对象

    • (instancetype)init NS_DESIGNATED_INITIALIZER;

    // these methods can only be set before a launch
    //指定NStask调用一个程序时的执行路径
    @property (nullable, copy) NSString *launchPath;
    //指定NStask调用一个程序时传入的参数
    @property (nullable, copy) NSArray<NSString *> *arguments;
    //设置 NStask执行另一个程序时,另一个程序运行时的环境变量
    @property (nullable, copy) NSDictionary<NSString *, NSString *> *environment; // if not set, use current
    //设置NStask执行另一个程序时,另一个程序的当前工作目录
    @property (copy) NSString *currentDirectoryPath; // if not set, use current

    // standard I/O channels; could be either an NSFileHandle or an NSPipe
    //设置NStask执行另一个程序时,另一个程序的标准输入
    @property (nullable, retain) id standardInput;
    //设置NStask执行另一个程序时,另一个程序的标准输出
    @property (nullable, retain) id standardOutput;
    //设置NStask执行另一个程序时,另一个程序的错误
    @property (nullable, retain) id standardError;

    // actions
    //启动另一个程序

    • (void)launch;
      //发送interrupt信号给NStask启动的另外一个程序和子进程
    • (void)interrupt; // Not always possible. Sends SIGINT.
      //发送terminate信号给NStask启动的另外一个程序和子进程
    • (void)terminate; // Not always possible. Sends SIGTERM.

    //暂停NStask调用的另外一个程序

    • (BOOL)suspend;
      //恢复NStask调用的另一个程序
    • (BOOL)resume;

    // status
    //NStask调用的另一个程序的进程标识符
    @property (readonly) int processIdentifier;
    //NStask调用的另外一个程序是否在运行中
    @property (readonly, getter=isRunning) BOOL running;

    //NStask调用的另外一个程序的退出状态
    @property (readonly) int terminationStatus;
    //NStask 调用的另外一个程序的退出原因
    @property (readonly) NSTaskTerminationReason terminationReason NS_AVAILABLE(10_6, NA);

    /*
    A block to be invoked when the process underlying the NSTask terminates. Setting the block to nil is valid, and stops the previous block from being invoked, as long as it hasn't started in any way. The NSTask is passed as the argument to the block so the block does not have to capture, and thus retain, it. The block is copied when set. Only one termination handler block can be set at any time. The execution context in which the block is invoked is undefined. If the NSTask has already finished, the block is executed immediately/soon (not necessarily on the current thread). If a terminationHandler is set on an NSTask, the NSTaskDidTerminateNotification notification is not posted for that task. Also note that -waitUntilExit won't wait until the terminationHandler has been fully executed. You cannot use this property in a concrete subclass of NSTask which hasn't been updated to include an implementation of the storage and use of it.
    */
    //NStask调用的另外一个程序的终止时的回调block
    @property (nullable, copy) void (^terminationHandler)(NSTask *) NS_AVAILABLE(10_7, NA);
    //质量服务
    @property NSQualityOfService qualityOfService NS_AVAILABLE(10_10, 8_0); // read-only after the task is launched

    @end

    @interface NSTask (NSTaskConveniences)

    //创建并启动另一个程序,可以指定传入的参数,这是一个类的方法,用起来比较方便

    • (NSTask *)launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray<NSString *> *)arguments;
      // convenience; create and launch

    //直到另一个程序运行结束,相应程序才会往下执行

    • (void)waitUntilExit;
      // poll the runLoop in defaultMode until task completes

    @end

    FOUNDATION_EXPORT NSNotificationName const NSTaskDidTerminateNotification;

    NS_ASSUME_NONNULL_END

    @end

  • 相关阅读:
    mini2440移植uboot 2014.04(四)
    mini2440移植uboot 2014.04(三)
    【这些年】Linux C/C++软件开发用过的工具
    Valgrind的Memcheck快速入门
    《浪潮之巅》读后感
    三层浅析及示例分析
    C语言的代码内存布局详解
    超级立方体小记
    如何和项目经理沟通产品的交付?
    CentOS配置smaba与Windows共享文件
  • 原文地址:https://www.cnblogs.com/xulinmei/p/7780621.html
Copyright © 2011-2022 走看看