shell Drop_caches by app不起作用

bksxznpy  于 2023-10-23  发布在  Shell
关注(0)|答案(3)|浏览(153)

我写了这个脚本,但不起作用:

package com.mkyong.android;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import com.example.toast.R;

public class MainActivity extends Activity {

private Button button;

public void onCreate(Bundle savedInstanceState) {
    final Runtime runtime = Runtime.getRuntime();
    try {
        runtime.exec("su");
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab1);

    button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new OnClickListener() {
        @SuppressLint("SdCardPath")
        @Override
        public void onClick(View arg0) {
            final Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("echo 3 > /proc/sys/vm/drop_caches");
                Toast.makeText(MainActivity.this, "Script lanciato con `successo, memoria svuotata.", Toast.LENGTH_LONG).show();`
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
}

不释放RAM内存:(但通过终端模拟器去。.如果我尝试更改命令,例如,使一个目录与mkdir去,去甚至一个文件txt的写作。.怎么了?

xmakbtuz

xmakbtuz1#

您的runtime.exec("su");刚刚启动了一个shell进程。下一个"runtime.exec("echo 3 > xxx")";不会在第一个shell中执行。
我的建议是坚持使用java.lang.process,启动一个执行“su”的进程,并使用重定向的stdin向其写入命令。

cvxl0en2

cvxl0en22#

你可以试试这个

try {
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "echo 3 > /proc/sys/vm/drop_caches" });
proc.waitFor();
} catch (Exception e) {
Log.d("Exceptions", "Exception dropping caches: "+e);
}

Process p=null;
            try {
                p = new ProcessBuilder()
                .command("PathToYourScript")
                .start();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if(p!=null) p.destroy();
            }
lf3rwulv

lf3rwulv3#

导入请求
def login(devil_bilal_45,devilkaif):和以前一样...
def report_user(session,devil_bilal_45):和以前一样...

  • 列表项

ifname==“main":#将'your_username'和'your_devilkaif'替换为您的实际Instagram凭据devil_bilal_45' = 'devil_bilal_45' Devilkaif '='devilkaif'

user_id_to_report = 'devil_bilal_45'   'devil_bilal_45' with the user ID of the profile you want to report
num_reports = 100

session = login(devil_bilal_45, devilkaif)

for i in range(num_reports):
    report_user(session, user_id_to_report)
    print(f"Report {i + 1} completed.")

print("All reports completed

相关问题