strace shell command issue in Android

2019-09-12 09:45发布

I'm building a monitor app, which runs in background and logs the system calls executed by currently running application using the strace command.

String cmd="strace -p "+processID+" -o /mnt/sdcard/traceFile_"+processID+".txt";
Runtime.getRuntime().exec(cmd);

Here processID is the PID of currently running process which is got from some other method implemented. It logs the system calls of the first app it monitors properly with all executed system call information. But when a new app is started(second one onwards), the processID is updated correctly, but the file traceFile_processID is written as an empty file. I'm not able to figure out why its happening. Is it because the strace execution of first app monitored still there?? If so how I can execute a ^C to terminate that session and start a new one as in adb shell command prompt?? Plz help me.....

1条回答
Bombasti
2楼-- · 2019-09-12 10:29

If you want to "^C" as you say, what you're really asking for is how to raise the signal called SIGINT to the given processID. You can do that simply by kill(processID, SIGINT); - this is equivalent to pressing Ctrl-C on the keyboard for the target process.

查看更多
登录 后发表回答