In Java, I can have something like this:
Process p = Runtime.getRuntime().exec("su");
DataOutputStream pOut = new DataOutputStream(p.getOutputStream());
pOut.writeBytes("find / -perm -2000 -o -perm -4000\n");
pOut.writeBytes("ps\n");
pOut.writeBytes("ls\n");
pOut.writeBytes("exit\n");
pOut.flush();
p.waitFor();
I know that to execute the find command in JNI method, we can use system or popen function. But I don't know how to execute it with su privilege?
PS: Since the system function forks a new child process. I want to have a single child process spawning up to execute multiple commands like in Java.