Class

NSProcessInfo

A collection of information about the current process. 現在のプロセスについての情報のコレクション。

Declaration 宣言

@interface NSProcessInfo : NSObject

Overview 概要

Each process has a single, shared NSProcessInfo object known as a process information agent that can return information such as arguments, environment variables, host name, and process name. The processInfo class method returns the shared agent for the current process. For example, the following line returns the NSProcessInfo object, which then provides the name of the current process: 各プロセスは、ある単一の、共有NSProcessInfoオブジェクトを、プロセス情報エージェントとして知られるものを持ちます、それは引数、環境変数、ホスト名、およびプロセス名のような情報を返すことができます。processInfoクラスメソッドは、現在のプロセスに対する共有エージェントを返します。たとえば、以下の行は、NSProcessInfoオブジェクトを返します、それはそれから現在のプロセスの名前を提供します:


NSString *processName = [[NSProcessInfo processInfo] processName];

The NSProcessInfo class also includes the operatingSystem method, which returns an enumeration constant identifying the operating system on which the process is executing. NSProcessInfoクラスはまたoperatingSystemメソッドを含みます、それはそれの上でそのプロセスが遂行されているところのオペレーティングシステムを識別するある列挙定数を返します。

NSProcessInfo objects attempt to interpret environment variables and command-line arguments in the user’s default C string encoding if they can’t convert to Unicode as UTF-8 strings. If neither the Unicode nor C string conversion works, the NSProcessInfo object ignores these values. NSProcessInfoオブジェクトは、環境変数とコマンドライン引数をユーザのもつ省略時のC文字列エンコーディングにおいて解釈しようと、もしそれらがUTF-8文字列としてユニコードへと変換できないならば試みます。ユニコードまたはC文字列変換のどちらも機能しないならば、NSProcessInfoオブジェクトはこれらの値を無視します。

Manage Activities アクティビティ(活動状態)を管理する

The system has heuristics to improve battery life, performance, and responsiveness of applications for the benefit of the user. You can use the following methods to manage activities that give hints to the system that your application has special requirements: システムは、バッテリー寿命、性能、そしてアプリケーションの応答性をユーザの利益のために改善する発見的手法を持ちます。あなたは、以下のメソッドを使ってアクティビティを管理できます、それは、システムにあなたのアプリケーションが特別な要件を持つというヒントを与えます:

In response to creating an activity, the system disables some or all of the heuristics so your application can finish quickly while still providing responsive behavior if the user needs it. あるアクティビティを作成することに答えて、システムは発見的手法の幾つかまたは全てを作動しないようにします、それであなたのアプリケーションは素早くやり終えることができ、その一方で依然として応答性の挙動を提供します、もしユーザがそれを必要とするならば。

You use activities when your application performs a long-running operation. If the activity can take different amounts of time (for example, calculating the next move in a chess game), it should use this API to ensure correct behavior when the amount of data or the capabilities of the user’s computer varies. Activities fall into two major categories: あなたがアクティビティを使うのは、あなたのアプリケーションが長期動作の演算を実行する場合です。そのアクティビティが異なる量の時間をとる可能性があるならば(例えば、チェスゲームでの次の動きの計算)、それはこのAPIを使うことで、データ量またはユーザのコンビューターの潜在能力がさまざまである時に正しい挙動を確実にするべきです。アクティビティそれらは、2つの主要カテゴリに帰属します:

  • User-initiated activities are explicitly started by the user. Examples include exporting or downloading a user-specified file. ユーザ着手アクティビティは、明示的にユーザによって開始されます。例としては、ユーザ指定のファイルのエクスポート(移出)やダウンロードが含まれます。

  • Background activities perform the normal operations of your application and aren’t explicitly started by the user. Examples include autosaving, indexing, and automatic downloading of files. バックグラウンド(背景)アクティビティは、あなたのアプリケーションの通常の演算を実行します、そしてユーザによって明示的に開始されません。例としては、自動保存、索引作成、そしてファイルの自動ダウンロードが含まれます。

In addition, if your application requires high priority input/output (I/O), you can include the NSActivityLatencyCritical flag (using a bitwise OR). You should only use this flag for activities like audio or video recording that require high priority I/O. 加えて、あなたのアプリケーションが高い優先順位の入力/出力(I/O)を要求するならば、あなたはNSActivityLatencyCriticalフラグを含めることができます(ビット単位ORを使って)。あなたは、このフラグを音声や映像の記録のようなアクティビティに対してのみ使用すべきです、それらは高い優先順位 I/O を必要とします。

If your activity takes place synchronously inside an event callback on the main thread, you don’t need to use this API. あなたのアクティビティがメインスレッド上のあるイベントコールバック内部で同期的に起こるならば、あなたはこのAPIを使う必要はありません。

Be aware that failing to end these activities for an extended period of time can have significant negative impacts on the performance of your user’s computer, so be sure to use only the minimum amount of time required. User preferences may override your application’s request. 自覚してください、これらアクティビティを長期間にわたり終了し損なうことは、重大な悪影響をあなたのユーザのもつコンピュータの性能に与える可能性があります、なので必要とされる最小限の時間だけ使うことを確実にしてください。ユーザ環境設定は、あなたのアプリケーションの要求をオーバーライドするかもしれません。

You can also use this API to control automatic termination or sudden termination (see Support Sudden Termination). For example, the following code brackets the work to protect it from sudden termination: あなたはまた、このAPIを使って自動終了または即時終了を制御できます(即時終了をサポートするを見てください)。例えば、以下のコードは、作業を角括弧で囲むことでそれを即時終了から保護します:


id activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityAutomaticTerminationDisabled reason:@"Good Reason"];
// Perform some work.
[[NSProcessInfo processInfo] endActivity:activity];

The above example is equivalent to the following code, which uses the disableAutomaticTermination: method: 上の例は、以下のコードに等しいです、それはdisableAutomaticTermination:メソッドを使います:


[[NSProcessInfo processInfo] disableAutomaticTermination:@"Good Reason"];
// Perform some work.
[[NSProcessInfo processInfo] enableAutomaticTermination:@"Good Reason"];

Because this API returns an object, it may be easier to pair begins and ends than when using the automatic termination API. If your app deallocates the object before the endActivity: call, the activity ends automatically. このAPIがあるオブジェクトを返すことから、始まりと終わりを対にするのは自動終了APIを使う場合よりも簡単かもしれません。あなたのアプリがそのオブジェクトをendActivity:呼び出しの前にデアロケートするならば、そのアクティビティは自動的に終わります。

This API also provides a mechanism to disable system-wide idle sleep and display idle sleep. These can have a large impact on the user experience, so be careful to end activities that disable sleep (including NSActivityUserInitiated). このAPIはまた、システム全体の休眠とディスプレイの休眠に対する仕組みを提供します。これらは、ユーザ体験に大きな影響を与えます、なのでスリープを作動しなくするアクティビティを終了するように気をつけてください(NSActivityUserInitiatedを含めて)。

Support Sudden Termination 即時終了をサポートする

macOS 10.6 and later includes a mechanism that allows the system to log out or shut down more quickly by, whenever possible, killing applications instead of requesting that they quit themselves. macOS 10.6以降はある仕組みを含み、それはシステムにより素早いログアウトやシャットダウンを許可します、可能ならいつでもアプリケーションそれらをキルする(殺す)ことによって、それらがそれら自身を終了するように要請する代わりに。

Your application can enable this capability on a global basis and then manually override its availability during actions that could cause data corruption or a poor user experience by allowing sudden termination. あなたのアプリケーションは、この能力を全面的規模で利用可能にして、それから手動でそれの利用可能性をオーバーライドすることがデータ汚染または貧弱なユーザ体験を即時終了の許可によって引き起こしうる動作の間に行えます。

Alternatively, your application can manually enable and disable this functionality. Creating a process assigns a counter that indicates if the process is safe to terminate. You decrement and increment the counter using the methods enableSuddenTermination and disableSuddenTermination. A value of 0 enables the system to terminate the process without first sending a notification or event. あるいはまた、あなたのアプリケーションはこの機能性を手動で作動せさたり作動しないようにできます。あるプロセスを作成することは、あるカウンターを割り当てます、それはそのプロセスが終了するのに安全かどうかを指し示します。あなたは、そのカウンターの漸増および漸減をメソッドenableSuddenTerminationおよびdisableSuddenTerminationを使って行います。0の値は、システムにそのプロセスの終了を、最初にある通知またはイベントを送信することなしに可能にします。

Your application can support sudden termination upon launch by adding a key to the application’s Info.plist file. If the NSSupportsSuddenTermination key exists in the Info.plist file and has a value of YES, it’s the equivalent of calling enableSuddenTermination during your application launch. This allows the system to terminate the process immediately. You can still override this behavior by invoking disableSuddenTermination. あなたのアプリケーションは、あるキーをアプリケーションのもつInfo.plistファイルに加えることによって、起動時に即時終了をサポートできます。NSSupportsSuddenTerminationキーがInfo.plistファイルの中に存在してYESの値を持つならば、それはenableSuddenTerminationをあなたのアプリケーション起動の間に呼び出すことに相当します。これは、システムにそのプロセスを直ぐに終了することを許可します。あなたは、依然としてこの挙動をオーバーライドすることがdisableSuddenTerminationを発動することで可能です。

Typically, you disable sudden termination whenever your app defers work that the app must complete before it terminates. If, for example, your app defers writing data to disk and enables sudden termination, you should bracket the sensitive operations with a call to disableSuddenTermination, perform the necessary operations, and then send a balancing enableSuddenTermination message. 概して、あなたは即時終了を作動しないようにします、あなたのアプリがそれが終了する前に完了しなければならない仕事を延期する時はいつでも。例えば、あなたのアプリがデータのディスクへの書き込みを延期するそして即時終了を可能にするならば、あなたは注意を要する演算それらをdisableSuddenTerminationへの呼び出しとともに角括弧で囲って、その不可欠な演算それらを実行して、それから収支を合わせるenableSuddenTerminationメッセージを送るべきです。

In agents or daemon executables that don’t depend on AppKit, you can manually invoke enableSuddenTermination right away. You can then use the enable and disable methods whenever the process has work it must do before it terminates. AppKitに依存しないエージェントまたはデーモン実行可能ファイルでは、あなたは手動でenableSuddenTerminationをすぐ発動できます。あなたはそれから使用可能および使用不能にするメソッドを、そのプロセスがそれが終了する前にそれが行わなければならない仕事を持つ場合はいつでも使用できます。

Some AppKit functionality automatically disables sudden termination on a temporary basis to ensure data integrity. いくらかのAppKit機能性は自動的に即時終了を一時的に使用不能にして、データ完全性を確かなものにします。

  • NSUserDefaults temporarily disables sudden termination to prevent the process from terminating between the time at which it sets the default and the time at which it writes the preferences file — including that default — to disk. NSUserDefaultsは、一時的に即時終了を使用不能にすることでプロセスの終了を、それが初期状態を設定する時間とそれが初期設定ファイルを書き出す時間のあいだ防止します。

  • NSDocument temporarily disables sudden termination to prevent the process from terminating between the time at which the user has made a change to a document and the time at which NSDocument writes the user's change to disk. NSDocumentは、一時的に即時終了を使用不能にすることでプロセスの終了を、ユーザが変更をある書類にした時間とNSDocumentがユーザの変更がディスクに書き込む時間のあいだ防止します。

Monitor Thermal State to Adjust App Performance 温度状態を監視してアプリ性能を調整する

Thermal state indicates the level of heat generated by logic components as they run apps. As the thermal state increases, the system decreases heat by reducing the speed of the processors. Optimize your app’s performance by monitoring the thermal state and reducing system usage as the thermal state increases. Query the current state with thermalState to determine if your app needs to reduce system usage. You can register the NSProcessInfoThermalStateDidChangeNotification for notifications of a change in thermal state. For recommended actions, see NSProcessInfoThermalState. 温度状態は、論理回路部品それらによってそれらがアプリを実行するとき生成される熱の水準を指し示します。温度状態が漸増するにつれて、システムはプロセッサの速度を減少することによって熱を漸減します。あなたのアプリの性能を温度状態を監視することそしてシステム利用を温度状態が漸増するにつれて減らすことによって最適化してください。現在の状態をthermalStateで問いただすことで、あなたのアプリがシステム利用を減らす必要があるか決定してください。あなたは、NSProcessInfoThermalStateDidChangeNotificationを温度状態におけるある変化の通知のために登録できます。推奨される動作のために、NSProcessInfoThermalStateを見てください。

Topics 話題

Getting the Process Information Agent プロセス情報エージェントを取得する

Accessing Process Information プロセス情報にアクセスする

Accessing User Information ユーザ情報にアクセスする

Each user account in macOS has a full name (e.g., “Johnny Appleseed”) and an account name (e.g., “jappleseed”). You can view these names from the Users & Groups pane of System Preferences, and you can use either name to log in to your Mac. macOSにおける各ユーザアカウントは、完全な名前(たとえば、“Johnny Appleseed”)とアカウント名(たとえば、“jappleseed”)。あなたは、これら名前をシステム環境設定のユーザとグループペインから眺められます、そしてあなたはどちらの名前を使ってもあなたのMacにログインできます。

Sudden Application Termination 即時アプリケーション終了

Controlling Automatic Termination 自動終了を制御する

Getting Host Information ホスト情報を得る

Getting Computer Information コンピュータ情報を取得する

Managing Activities アクティビティ(活動状態)を管理する

Getting the Thermal State 温度状態を取得する

Determining Whether Low Power Mode is Enabled 低電力モードが可能にされるかどうか決定する

Constants 定数

Notifications 通知

Relationships 関係

Inherits From 継承元

See Also 参照

System Interaction システム相互作用