2019-03-03 04:08:54 +01:00
|
|
|
kill() Netscript Function
|
|
|
|
=========================
|
|
|
|
|
2023-02-24 12:57:17 +01:00
|
|
|
.. js:function:: kill(script[, hostname=current hostname[, args...]])
|
2019-03-03 04:08:54 +01:00
|
|
|
|
|
|
|
:RAM cost: 0.5 GB
|
2021-03-12 08:51:56 +01:00
|
|
|
:param string script: Filename of the script to kill.
|
2023-01-06 13:43:09 +01:00
|
|
|
:param string hostname: Hostname of the server on which to kill the script.
|
2021-03-12 08:51:56 +01:00
|
|
|
:param args...: Arguments to identify which script to kill.
|
|
|
|
:returns: ``true`` is that script was killed.
|
2019-03-03 04:08:54 +01:00
|
|
|
|
2021-03-12 08:51:56 +01:00
|
|
|
Kills the script on the target server specified by the script's name and
|
|
|
|
arguments. Remember that scripts are uniquely identified by both their name
|
2023-01-06 13:43:09 +01:00
|
|
|
and arguments. For example, if ``foo.js`` is run with the argument 1,
|
|
|
|
then this is not the same as ``foo.js`` run with the argument 2, even
|
2021-03-12 08:51:56 +01:00
|
|
|
though they have the same code.
|
2019-03-03 04:08:54 +01:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2023-01-06 13:43:09 +01:00
|
|
|
The following example will try to kill a script named ``foo.js`` on the
|
2021-03-12 08:51:56 +01:00
|
|
|
``foodnstuff`` server that was ran with no arguments:
|
|
|
|
|
|
|
|
.. code-block:: javascript
|
2019-03-03 04:08:54 +01:00
|
|
|
|
2023-01-06 13:43:09 +01:00
|
|
|
ns.kill("foo.js", "foodnstuff");
|
2019-03-03 04:08:54 +01:00
|
|
|
|
2023-01-06 13:43:09 +01:00
|
|
|
The following will try to kill a script named ``foo.js`` on the current
|
2021-03-12 08:51:56 +01:00
|
|
|
server that was ran with no arguments:
|
|
|
|
|
|
|
|
.. code-block:: javascript
|
2019-03-03 04:08:54 +01:00
|
|
|
|
2023-01-06 13:43:09 +01:00
|
|
|
ns.kill("foo.js");
|
2019-03-03 04:08:54 +01:00
|
|
|
|
2023-01-06 13:43:09 +01:00
|
|
|
The following will try to kill a script named ``foo.js`` on the current
|
2021-03-12 08:51:56 +01:00
|
|
|
server that was ran with the arguments 1 and "foodnstuff":
|
|
|
|
|
|
|
|
.. code-block:: javascript
|
2019-03-03 04:08:54 +01:00
|
|
|
|
2023-01-06 13:43:09 +01:00
|
|
|
ns.kill("foo.js", ns.getHostname(), 1, "foodnstuff");
|
2019-07-12 04:37:17 +02:00
|
|
|
|
|
|
|
.. js:function:: kill(scriptPid)
|
|
|
|
|
|
|
|
:RAM cost: 0.5 GB
|
2021-03-12 08:51:56 +01:00
|
|
|
:param number scriptPid: PID of the script to kill
|
|
|
|
:returns: ``true`` that script was killed.
|
2019-07-12 04:37:17 +02:00
|
|
|
|
2021-03-12 08:51:56 +01:00
|
|
|
Kills the script with the specified PID. Killing a script by its PID will
|
|
|
|
typically have better performance, especially if you have many scripts
|
|
|
|
running.
|
2019-07-12 04:37:17 +02:00
|
|
|
|
|
|
|
|
2021-03-12 08:51:56 +01:00
|
|
|
Example:
|
2019-07-12 04:37:17 +02:00
|
|
|
|
2021-03-12 08:51:56 +01:00
|
|
|
.. code-block:: javascript
|
2019-07-12 04:37:17 +02:00
|
|
|
|
2023-01-06 13:43:09 +01:00
|
|
|
if (ns.kill(10)) {
|
|
|
|
ns.print("Killed script with PID 10!");
|
2019-07-12 04:37:17 +02:00
|
|
|
}
|