mac 如何查看 java程序的进程id ?

方法1

ZBMAC-f2b04ccbd:~ liuyazhou$ jps

83505 KotlinCompileDaemon

93827 Launcher

45701 

93828 SynchronizedObject2

91464 JConsole

93868 Jps

ZBMAC-f2b04ccbd:~ liuyazhou$ 

93828是程序SynchronizedObject2的进程id

 

jps:虚拟机进程状况工具:查看当前运行的java进行,后面的许多命令都是基于此命令找到pid再进一步排查问题。

 

方法2

尝试在终端中使用ps aux | grep APP_NAME

92249 就是这个Java应用的进程id

jdk1.8 版本

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Java 海康是指使用 Java 语言编写的海康威视(Hikvision)网络视频监控系统。在这个系统中,可以通过编写代码来实现文件的保存操作。下面是一个简单的示例: ``` import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.ByteByReference; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; import com.sun.jna.ptr.ShortByReference; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.sun.jna.Memory; import com.sun.jna.Native; import com.sun.jna.Structure; import com.sun.jna.win32.StdCallLibrary; public class SaveFileUtil { private static final Logger log = LoggerFactory.getLogger(SaveFileUtil.class); // 海康SDK的调用 static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE; // 海康SDK所需的DLL文件路径 static { String osName = System.getProperty("os.name").toLowerCase(); String libName = "hcnetsdk"; if (osName.startsWith("win")) { libName += ".dll"; } else if (osName.startsWith("linux")) { libName += ".so"; } else if (osName.startsWith("mac os x")) { libName += ".dylib"; } String libPath = SaveFileUtil.class.getResource("/" + libName).getPath(); Native.register(StdCallLibrary.DEFAULT_LIBRARY_NAME, HCNetSDK.class.getResource("/lib/" + libName).getFile()); } /** * 下载海康录像文件并保存到本地 * * @param ip 设备的IP地址 * @param port 端口号 * @param userName 登录用户名 * @param password 登录密码 * @param filePath 文件保存路径 * @param fileName 文件名 * @param channel 通道号 * @param startTime 文件开始时间 * @param endTime 文件结束时间 * @return true:保存成功 false:保存失败 */ public static boolean saveHikFile(String ip, int port, String userName, String password, String filePath, String fileName, int channel, String startTime, String endTime) { // 登录设备 NativeLong lUserID = login(ip, port, userName, password); if (lUserID.longValue() < 0) { log.error("登录设备失败,错误代码:" + hCNetSDK.NET_DVR_GetLastError()); return false; } // 下载录像文件 NativeLong lHandle = downloadFile(lUserID, channel, startTime, endTime); if (lHandle.longValue() < 0) { log.error("下载录像文件失败,错误代码:" + hCNetSDK.NET_DVR_GetLastError()); hCNetSDK.NET_DVR_Logout(lUserID); return false; } // 下载文件数据 int nBytes = 0; byte[] buffer = new byte[64 * 1024]; FileOutputStream fos = null; try { File fileDir = new File(filePath); if (!fileDir.exists()) { fileDir.mkdirs(); } File file = new File(fileDir, fileName); if (file.exists()) { file.delete(); } file.createNewFile(); fos = new FileOutputStream(file); // 循环读取文件数据并写入本地文件 while (true) { IntByReference pBufferLen = new IntByReference(0); PointerByReference pPacketBuffer = new PointerByReference(); boolean bRet = hCNetSDK.NET_DVR_GetNextRemoteFile(lHandle, pPacketBuffer, pBufferLen); if (!bRet) { log.info("下载文件完成【" + file.getName() + "】,总计大小:" + file.length() + " byte"); break; } // 获取包数据 Memory memory = new Memory(pBufferLen.getValue() + 4); memory.write(0, pPacketBuffer.getValue().getByteArray(0, pBufferLen.getValue()), 0, pBufferLen.getValue()); // 获取数据指针 Pointer pData = memory.getPointer(0); if (pData == null) { continue; } // 获取数据长度 nBytes = pBufferLen.getValue(); if (nBytes < 0) { continue; } // 写入数据到本地文件 byte[] data = pData.getByteArray(0, nBytes); fos.write(data); fos.flush(); } fos.close(); hCNetSDK.NET_DVR_StopGetFile(lHandle); hCNetSDK.NET_DVR_Logout(lUserID); return true; } catch (IOException e) { log.error(e.getMessage(), e); return false; } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { log.error(e.getMessage(), e); } } } } // 登录海康设备 private static NativeLong login(String ip, int port, String userName, String password) { HCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO(); HCNetSDK.NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = new HCNetSDK.NET_DVR_DEVICEINFO_V40(); // 设置登录信息 struLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN]; System.arraycopy(ip.getBytes(), 0, struLoginInfo.sDeviceAddress, 0, ip.length()); struLoginInfo.wPort = (short) port; struLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN]; System.arraycopy(userName.getBytes(), 0, struLoginInfo.sUserName, 0, userName.length()); struLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN]; System.arraycopy(password.getBytes(), 0, struLoginInfo.sPassword, 0, password.length()); // 登录 NativeLong lUserID = hCNetSDK.NET_DVR_Login_V40(struLoginInfo, struDeviceInfoV40); return lUserID; } // 下载海康文件 private static NativeLong downloadFile(NativeLong lUserID, int channel, String startTime, String endTime) { HCNetSDK.NET_DVR_MATRIX_PARA_V30 struMatrixPara = new HCNetSDK.NET_DVR_MATRIX_PARA_V30(); struMatrixPara.byStreamType = 0; struMatrixPara.byChannel = new byte[] { (byte) channel }; struMatrixPara.dwStreamID = 0; struMatrixPara.dwLinkMode = 0x40000000; // 设置下载参数 HCNetSDK.NET_DVR_PLAYCOND struDownloadCond = new HCNetSDK.NET_DVR_PLAYCOND(); struDownloadCond.struStartTime = new HCNetSDK.NET_DVR_TIME(); struDownloadCond.struStartTime.dwYear = Integer.parseInt(startTime.substring(0, 4)); struDownloadCond.struStartTime.dwMonth = Integer.parseInt(startTime.substring(5, 7)); struDownloadCond.struStartTime.dwDay = Integer.parseInt(startTime.substring(8, 10)); struDownloadCond.struStartTime.dwHour = Integer.parseInt(startTime.substring(11, 13)); struDownloadCond.struStartTime.dwMinute = Integer.parseInt(startTime.substring(14, 16)); struDownloadCond.struStartTime.dwSecond = Integer.parseInt(startTime.substring(17, 19)); struDownloadCond.struStopTime = new HCNetSDK.NET_DVR_TIME(); struDownloadCond.struStopTime.dwYear = Integer.parseInt(endTime.substring(0, 4)); struDownloadCond.struStopTime.dwMonth = Integer.parseInt(endTime.substring(5, 7)); struDownloadCond.struStopTime.dwDay = Integer.parseInt(endTime.substring(8, 10)); struDownloadCond.struStopTime.dwHour = Integer.parseInt(endTime.substring(11, 13)); struDownloadCond.struStopTime.dwMinute = Integer.parseInt(endTime.substring(14, 16)); struDownloadCond.struStopTime.dwSecond = Integer.parseInt(endTime.substring(17, 19)); // 下载文件 NativeLong lHandle = hCNetSDK.NET_DVR_GetFileByTime_V40(lUserID, new String[] { "0" }, 1, struMatrixPara, new HCNetSDK.NET_DVR_TIME(), new HCNetSDK.NET_DVR_TIME(), struDownloadCond); return lHandle; } } ``` 这里我们定义了一个名为 `SaveFileUtil` 的工具类,用于实现海康设备录像文件的下载和保存操作。该类中包含了 `saveHikFile` 方法,该方法需要传递以下参数: - `ip`:海康设备的IP地址; - `port`:设备端口号; - `userName`:登录用户名; - `password`:登录密码; - `filePath`:文件保存路径; - `fileName`:文件名; - `channel`:通道号; - `startTime`:文件开始时间; - `endTime`:文件结束时间。 该方法实现的过程如下: - 调用 `login` 方法登录海康设备,获取登录ID; - 调用 `downloadFile` 方法下载录像文件,获取文件句柄; - 通过句柄循环读取文件数据,并写入本地文件; - 关闭文件流、停止文件下载、注销登录。 以上就是使用 Java 海康保存文件的简单方法。需要注意的是,在运行该示例代码前,需要确保已经正确引入海康的SDK包,并且配置了必要的登录权限。如果需要更深入的了解海康SDK的使用,请参考海康官方文档或者参考其他的开源工具类库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二十六画生的博客

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值