Comments (2)
张孝家:想法一(不知道对不对,有问题大家指出来)
当我们用cmd.Start()开始启动python程序之后,cmd.Wait()之前,在这两个中间,我们可以从cmd结构体对象中Process对象中Pid字段,提取进程的pid号。然后,可以全局共享切片(保存int类型的切片),将进程的pid号保存到这个共享切片中。当我们ctrl-c的lmp的时候,我们可以捕捉到这个信号,在这个信号处理程序中,对切片中的进程pid号,通过syscall.kill()来杀死线程。用什么保存pid号,其实都可以,如切片、管道、数组、map我感觉都是可以的,但是我更倾向于切片。
想法二(不保存pid号,保存Process)
在cmd结构对象中,有个Process字段(这个字段的类型是os.Process),我们可以保存这个字段的信息到切片中。还是在cmd.Start()和cmd.Wait()之间来提取。然后,同样在ctrl-c lmp的时候,捕捉信号,在信号处理函数中,遍历切片。通过方法func (p *Process) Kill() error,来杀死进程。
from lmp.
张孝家:想法三(这种方法是我比较喜欢的,但是我不知道对不对。)
通过ctx来做这件事情,我们将创建ctx的的事件提前在主线程中做(保存到一个全局变量里面),在我们go execute的的时候,我们通过传入ctx参数,然后创建goroutine,来执行python程序。同样,当我们杀死lmp的时候,捕捉信号。在信号处理函数中,通过ctx.done()获取到通道。然后close()通道,就可以了。这样的话,你在go execute中创建的go func中select就会自动通过,自动的kill进程了(一个go func对应一个python,自己kill进程,而且go func也退出了,不仅python退出了,go func也退出了,两全齐美)。可能描述的不清楚。等开会的时候,可以探讨一下。
from lmp.
Related Issues (20)
- Process_image 项目:目标是开发一个Linux用户态进程生命周期画像工具 HOT 3
- Stack_Analyzer项目:基于eBPF的调用栈统计工具 HOT 6
- 使用eBPF优化FUSE read方法性能
- net_watcher项目:基于eBPF的无侵入式网络分析工具开发建设
- net_manager 项目:对 linux 内核网络进行优化和加速 HOT 2
- fast_fuse项目:使用eBPF优化FUSE read/write 等方法性能 HOT 4
- mem_watcher 项目:目标是分析主机中指定进程或者服务内存使用情况 HOT 1
- cpu_watcher 项目:目标是分析cpu 的运行状态 HOT 4
- kvm_watcher 项目:目标是分析 kvm 的状态信息 HOT 15
- cilium_ebpf_probe 代码编译需要修复
- sidecar 代码编译需要修复
- [BUG]get_loadavg.py中报错 HOT 2
- eBPF DNS Cache HOT 4
- BCC_sar下的各个功能整合到 cpu_watcher:
- fs_watcher项目:目标是检测文件系统的性能指标 HOT 10
- [BUG]get_loadavg HOT 1
- c++符号解析支持
- MagicEyes:Linux内核观测与诊断工具框架
- [BUG] compile eBPF_proc_image error HOT 1
- [BUG]ebpf_cpu_watcher.yml 流水线文件有语法错误,执行有问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lmp.