问题
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:
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.
来源:https://stackoverflow.com/questions/14796156/strace-shell-command-issue-in-android