编写deamon进程 把.c编译成an…
2014-03-10 17:05
323 查看
编写deamon进程
在vendor/cm/prebuilt/common/etc/nit.d目录下建立01xxx(必须以两位数开头),在里面写要执行的操作
比如,输出点什么
L="log -p i -t cm"
$L "____ _ _ ____
_ _ ____ ____ ____ _ _
_ _ ____ ___";
$L
"|
\\_/ |__| |\\ | | | | __ |___
|\\ | |\\/| | | | \\";
$L "|___
| | | | \\|
|__| |__] |___ | \\| | | |__| |__/";
$L "Welcome to Android `getprop ro.build.version.release` /
CyanogenMod-`getprop ro.cm.version`";
比如,运行点什么脚本
/system/bin/mipand
都是shell脚本,具体写法,可以模仿目录下面那两个文件00banner和90userinit
在/vendor/cm/config/common.mk 中,加上
# mipaninit support
PRODUCT_COPY_FILES += \
vendor/cm/prebuilt/common/etc/init.d/02mipan:system/etc/init.d/02mipan
这样,02mipan就会开机过程中自动启动了。
adb shell后可以通过pstree来查看到它
把.c编译成android用的可执行文件
然后,mipand是怎么来的捏?
首先pc上建个文件夹,mipand。最好在全英文路径下
mipand里面建文件夹jni
jni里面建一个弱弱的.c文件,要执行的动作放在里面
想要进程常驻的话,可以在main函数最后加上
while(1)
{
sleep(100);
}
为了让mipand能够被编译,还需要一个弱弱的Android.mk文件
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS :=optional
LOCAL_SRC_FILES:= mipand.c
LOCAL_MODULE:= mipand
LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
LOCAL_PRELINK_MODULE := false
include $(BUILD_EXECUTABLE)
使用ndk把它编译成.d文件,这里使用的是android-ndk-r8e
需要把它的路径加到环境变量里。
在~/.profile里加入
PATH="/xxxx/xxxx/android-ndk-r8e:$PATH"
NDK="/xxxx/xxxx//android-ndk-r8e"
source一下这个.profile,然后,在mipand路径下运行ndk-build
正常的话,会在mipand/libs/armeabi下出现mipand可执行文件
这个可执行文件是android可以用的了
可以运行
adb root
remount -o rw,remount -t rootfs /system
adb push /xxx/mipand/libs/armeabi/mipand /system/bin/
把这可执行文件发到手机的/system/bin/目录下
可执行文件自己爬去/system/bin/
首先,mipand这货,得拷贝到android源码目录当中去,比如,我放到了vendor/cm/prebuilt/mipan/目录下,mipan是自己建的,这不重要,只要这个放置mipand的路径跟后面的操作对应上就可以了
在/vendor/cm/config/common.mk 中,加上
PRODUCT_COPY_FILES += \
vendor/cm/prebuilt/mipan/mipand:system/bin/mipand
在vendor/cm/prebuilt/common/etc/nit.d目录下建立01xxx(必须以两位数开头),在里面写要执行的操作
比如,输出点什么
L="log -p i -t cm"
$L "____ _ _ ____
_ _ ____ ____ ____ _ _
_ _ ____ ___";
$L
"|
\\_/ |__| |\\ | | | | __ |___
|\\ | |\\/| | | | \\";
$L "|___
| | | | \\|
|__| |__] |___ | \\| | | |__| |__/";
$L "Welcome to Android `getprop ro.build.version.release` /
CyanogenMod-`getprop ro.cm.version`";
比如,运行点什么脚本
/system/bin/mipand
都是shell脚本,具体写法,可以模仿目录下面那两个文件00banner和90userinit
在/vendor/cm/config/common.mk 中,加上
# mipaninit support
PRODUCT_COPY_FILES += \
vendor/cm/prebuilt/common/etc/init.d/02mipan:system/etc/init.d/02mipan
这样,02mipan就会开机过程中自动启动了。
adb shell后可以通过pstree来查看到它
把.c编译成android用的可执行文件
然后,mipand是怎么来的捏?
首先pc上建个文件夹,mipand。最好在全英文路径下
mipand里面建文件夹jni
jni里面建一个弱弱的.c文件,要执行的动作放在里面
想要进程常驻的话,可以在main函数最后加上
while(1)
{
sleep(100);
}
为了让mipand能够被编译,还需要一个弱弱的Android.mk文件
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS :=optional
LOCAL_SRC_FILES:= mipand.c
LOCAL_MODULE:= mipand
LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
LOCAL_PRELINK_MODULE := false
include $(BUILD_EXECUTABLE)
使用ndk把它编译成.d文件,这里使用的是android-ndk-r8e
需要把它的路径加到环境变量里。
在~/.profile里加入
PATH="/xxxx/xxxx/android-ndk-r8e:$PATH"
NDK="/xxxx/xxxx//android-ndk-r8e"
source一下这个.profile,然后,在mipand路径下运行ndk-build
正常的话,会在mipand/libs/armeabi下出现mipand可执行文件
这个可执行文件是android可以用的了
可以运行
adb root
remount -o rw,remount -t rootfs /system
adb push /xxx/mipand/libs/armeabi/mipand /system/bin/
把这可执行文件发到手机的/system/bin/目录下
可执行文件自己爬去/system/bin/
首先,mipand这货,得拷贝到android源码目录当中去,比如,我放到了vendor/cm/prebuilt/mipan/目录下,mipan是自己建的,这不重要,只要这个放置mipand的路径跟后面的操作对应上就可以了
在/vendor/cm/config/common.mk 中,加上
PRODUCT_COPY_FILES += \
vendor/cm/prebuilt/mipan/mipand:system/bin/mipand
相关文章推荐
- Fedora 重启xinetd服务进程
- linux下编译wpa_supplicant …
- Linux init进程
- Oracle 进程类别
- Tachyon 0.7.1源码的编译
- 编译原理笔记8 自上而下语法分析-…
- ios ipa文件反编译
- android activity启动另一个进程的…
- An API for interacting with Star…
- IAR编译常见错误 【转】
- 0820-0821 进程
- keilc 4 编译出现的几个错误…
- 在ubuntu中编译内核是用make …
- 使用codeblock 编译工程发出警告:"Debug" uses an invalid compiler. Skipping...
- 列举 Windows 所有进程…
- Centos 5.7 x86_64环境下编译CDH …
- linux 进程管理之jobs
- 编译原理笔记9 自上而下语法分析-…
- Linux:Qt的编译和安装配置 (本…
- windows 无窗口进程间消息通…