参数 | 详解 |
---|---|
-a | Audible ping. |
-A | 自适应ping,根据ping包往返时间确定ping的速度; |
-b | 允许ping一个广播地址; |
-B | 不允许ping改变包头的源地址; |
-c count | ping指定次数后停止ping; |
-d | 使用Socket的SO_DEBUG功能; |
-F flow_label | 为ping回显请求分配一个20位的“flow label”,如果未设置,内核会为ping随机分配; |
-f | 极限检测,快速连续ping一台主机,ping的速度达到100次每秒; |
-i interval | 设定间隔几秒发送一个ping包,默认一秒ping一次; |
-I interface | 指定网卡接口、或指定的本机地址送出数据包; |
-l preload | 设置在送出要求信息之前,先行发出的数据包; |
-L | 抑制组播报文回送,只适用于ping的目标为一个组播地址 |
-n | 不要将ip地址转换成主机名; |
-p pattern | 指定填充ping数据包的十六进制内容,在诊断与数据有关的网络错误时这个选项就非常有用,如:“-p ff”; |
-q | 不显示任何传送封包的信息,只显示最后的结果 |
-Q tos | 设置Qos(Quality of Service),它是ICMP数据报相关位;可以是十进制或十六进制数,详见rfc1349和rfc2474文档; |
-R | 记录ping的路由过程(IPv4 only); 注意:由于IP头的限制,最多只能记录9个路由,其他会被忽略; |
-r | 忽略正常的路由表,直接将数据包送到远端主机上,通常是查看本机的网络接口是否有问题;如果主机不直接连接的网络上,则返回一个错误。 |
-S sndbuf | Set socket sndbuf. If not specified, it is selected to buffer not more than one packet. |
-s packetsize | 指定每次ping发送的数据字节数,默认为“56字节”+“28字节”的ICMP头,一共是84字节; 包头+内容不能大于65535,所以最大值为65507(linux:65507, windows:65500); |
-t ttl | 设置TTL(Time To Live)为指定的值。该字段指定IP包被路由器丢弃之前允许通过的最大网段数; |
-T timestamp_option | 设置IP timestamp选项,可以是下面的任何一个: 'tsonly' (only timestamps) 'tsandaddr' (timestamps and addresses) 'tsprespec host1 [host2 [host3]]' (timestamp prespecified hops). |
-M hint | 设置MTU(最大传输单元)分片策略。 可设置为: 'do':禁止分片,即使包被丢弃; 'want':当包过大时分片; 'dont':不设置分片标志(DF flag); |
-m mark | 设置mark; |
-v | 使ping处于verbose方式,它要ping命令除了打印ECHO-RESPONSE数据包之外,还打印其它所有返回的ICMP数据包; |
-U | Print full user-to-user latency (the old behaviour). Normally ping prints network round trip time, which can be different f.e. due to DNS failures. |
-W timeout | 以毫秒为单位设置ping的超时时间; |
-w deadline | deadline; |
3.1.Runtime
好,最后重点说一下Runtime,他在java.lang包下面,
/** * Executes the specified command and its arguments in a separate native * process. The new process inherits the environment of the caller. Calling * this method is equivalent to calling {@code exec(progArray, null, null)}. * * @param progArray * the array containing the program to execute as well as any * arguments to the program. * @return the new {@code Process} object that represents the native * process. * @throws IOException * if the requested program can not be executed. */ public Process exec(String[] progArray) throws java.io.IOException { return exec(progArray, null, null); } /** * Executes the specified command and its arguments in a separate native * process. The new process uses the environment provided in {@code envp}. * Calling this method is equivalent to calling * {@code exec(progArray, envp, null)}. * * @param progArray * the array containing the program to execute as well as any * arguments to the program. * @param envp * the array containing the environment to start the new process * in. * @return the new {@code Process} object that represents the native * process. * @throws IOException * if the requested program can not be executed. */ public Process exec(String[] progArray, String[] envp) throws java.io.IOException { return exec(progArray, envp, null); } /** * Executes the specified command and its arguments in a separate native * process. The new process uses the environment provided in {@code envp} * and the working directory specified by {@code directory}. * * @param progArray * the array containing the program to execute as well as any * arguments to the program. * @param envp * the array containing the environment to start the new process * in. * @param directory * the directory in which to execute the program. If {@code null}, * execute if in the same directory as the parent process. * @return the new {@code Process} object that represents the native * process. * @throws IOException * if the requested program can not be executed. */ public Process exec(String[] progArray, String[] envp, File directory) throws IOException { // ProcessManager is responsible for all argument checking. return ProcessManager.getInstance().exec(progArray, envp, directory, false); } /** * Executes the specified program in a separate native process. The new * process inherits the environment of the caller. Calling this method is * equivalent to calling {@code exec(prog, null, null)}. * * @param prog * the name of the program to execute. * @return the new {@code Process} object that represents the native * process. * @throws IOException * if the requested program can not be executed. */ public Process exec(String prog) throws java.io.IOException { return exec(prog, null, null); } /** * Executes the specified program in a separate native process. The new * process uses the environment provided in {@code envp}. Calling this * method is equivalent to calling {@code exec(prog, envp, null)}. * * @param prog * the name of the program to execute. * @param envp * the array containing the environment to start the new process * in. * @return the new {@code Process} object that represents the native * process. * @throws IOException * if the requested program can not be executed. */ public Process exec(String prog, String[] envp) throws java.io.IOException { return exec(prog, envp, null); } /** * Executes the specified program in a separate native process. The new * process uses the environment provided in {@code envp} and the working * directory specified by {@code directory}. * * @param prog * the name of the program to execute. * @param envp * the array containing the environment to start the new process * in. * @param directory * the directory in which to execute the program. If {@code null}, * execute if in the same directory as the parent process. * @return the new {@code Process} object that represents the native * process. * @throws IOException * if the requested program can not be executed. */ public Process exec(String prog, String[] envp, File directory) throws java.io.IOException { // Sanity checks if (prog == null) { throw new NullPointerException("prog == null"); } else if (prog.isEmpty()) { throw new IllegalArgumentException("prog is empty"); } // Break down into tokens, as described in Java docs StringTokenizer tokenizer = new StringTokenizer(prog); int length = tokenizer.countTokens(); String[] progArray = new String[length]; for (int i = 0; i < length; i++) { progArray[i] = tokenizer.nextToken(); } // Delegate return exec(progArray, envp, directory); }
prog时需要执行的程序,怎么理解,其实很简单,就是系统的command命令,到这大家应该都清楚了,Android是Linux系统,这里的指令也就是Linux的命令了,例如ps(查看进程),ls,pwd(查看现在路径,文件等等)等等,大家都可以去试试。
1、exec的String prog只能执行一条指令,如果需要执行多条指令需要放入sh脚本文件中执行或者调用多次exec函数。
2、exec的String command不支持通配符(*)。
3、有些指令需要指定File dir(工作目录)。
4、默认的工作目录是根目录/。(通过执行指令pwd可查到)
5、导出logcat日志到SD卡ziyouku目录,参数:("logcat -df logcat.log",new File("/mnt/sdcard/ziyouku/"))
6、logcat读取权限:
好,今天就说这么多,最近在做Spingboot开发后台并发系统,所以写博客也是对之前项目的很多技术点的总结完善。