Linux中是否有一种方法可以使用C代码获取"ifconfig eth0"返回的相同信息?我对IP地址,链接状态和MAC地址等感兴趣.
这是ifconfig的示例输出:
eth0 Link encap:Ethernet HWaddr 00:0F:20:CF:8B:42
inet addr:217.149.127.10 Bcast:217.149.127.63 Mask:255.255.255.192
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2472694671 errors:1 dropped:0 overruns:0 frame:0
TX packets:44641779 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1761467179 (1679.8 Mb) TX bytes:2870928587 (2737.9 Mb)
Interrupt:28
Run Code Online (Sandbox Code Playgroud) 我有一个由第三方提供的bash脚本,它定义了一组函数.这是一个模板,看起来像什么
$ cat test.sh
#!/bin/bash
define go() {
echo "hello"
}
Run Code Online (Sandbox Code Playgroud)
我可以从bash shell中执行以下操作来调用go():
$ source test.sh
$ go
hello
Run Code Online (Sandbox Code Playgroud)
有没有办法从python脚本访问相同的功能?我尝试了以下,但它不起作用:
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call("source test.sh")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/subprocess.py", line 470, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child …Run Code Online (Sandbox Code Playgroud) 有没有人知道Android NDK下的本机C++代码的内存调试工具(如Valgrind)?
我正在研究一个多线程的项目,并且想知道是否有办法让编译器标记使用对C库的非重入调用(例如strtok_r的strtok intsead)?如果没有,是否有一个不可重入的调用列表,所以我可以定期查看我的代码库?
一个相关的问题是,是否有办法标记3d方库使用非重入调用.
我假设重入意味着线程安全,但不一定反过来.是否有充分的理由在线程项目中使用非重入调用?
将bash变量传递给python脚本的最佳方法是什么?我想做类似以下的事情:
$cat test.sh
#!/bin/bash
foo="hi"
python -c 'import test; test.printfoo($foo)'
$cat test.py
#!/bin/python
def printfoo(str):
print str
Run Code Online (Sandbox Code Playgroud)
当我尝试运行bash脚本时,出现语法错误:
File "<string>", line 1
import test; test.printfoo($foo)
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud) 以下代码在打印字符串后导致分段错误:
#include <iostream>
using namespace std;
int main()
{
cout << "ndktest" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
作为参考,这是我的Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndktest
LOCAL_SRC_FILES := main.cpp
include $(BUILD_EXECUTABLE)
Run Code Online (Sandbox Code Playgroud)
和Application.mk:
APP_STL := stlport_static
Run Code Online (Sandbox Code Playgroud)
这是来自logcat的崩溃:
I/DEBUG ( 872): pid: 4234, tid: 4234 >>> /data/ndktest <<<
I/DEBUG ( 872): signal 11 (SIGSEGV), fault addr 00024004
I/DEBUG ( 872): r0 00033824 r1 00001000 r2 00024005 r3 bea42cfc
I/DEBUG ( 872): r4 40008090 r5 0000000a r6 40008000 r7 afd42328 …Run Code Online (Sandbox Code Playgroud) 我使用的是Android 2.2,它附带了一个STLport版本.出于某种原因,它被配置为非线程安全的.这是在配置头文件中使用#define _NOTHREADS完成的.
当我从不同的pthreads 构造和初始化不同的非共享容器(例如字符串)时,我得到了内存损坏.
使用_NOTHREADS,看起来在allocator.cpp中的STL中的某些低级代码不能正确锁定.这似乎类似于C不为malloc提供线程安全性.
有谁知道为什么在Android上默认使用_NOTHREADS构建STL?通过关闭它,我想知道是否可能有副作用.我能想到的一件事是性能略有下降,但鉴于我使用了大量的线程,我没有看到太多的选择.
在下面的示例中,有没有办法知道合并发生了?看着git log,我不能告诉我合并了.
# setup example directory
$ mkdir test
$ cd test
$ git init
$ touch a
$ git add a
$ git commit -m "1"
# switch to different branch
$ git checkout -b topic
$ touch b
$ git add b
$ git commit -m "2"
# go back to master and merge
$ git checkout master
$ git merge topic
# git log
commit cccc64de3947828f487a8ce3c3e72b0f68dc88c3
Author: none
Date: Fri May 20 05:54:45 2011 -0700
2
commit …Run Code Online (Sandbox Code Playgroud) 我有一个使用openssl工具加密的bash脚本.
#!/bin/bash
key128="1234567890123456"
iv="1234567890123456"
openssl enc -aes-128-cbc -in test -out test.enc -K $key128 -iv $iv
Run Code Online (Sandbox Code Playgroud)
和试图解密脚本生成的文件的Java代码.
public class crypto {
public static void main( String[] args )
{
try {
File f = new File("test.enc");
Cipher c;
Key k;
String secretString = "01020304050607080900010203040506";
String ivString = "01020304050607080900010203040506";
byte[] secret = hexStringToByteArray(secretString);
byte[] iv = hexStringToByteArray(ivString);
c = Cipher.getInstance("AES/CBC/PKCS5Padding");
k = new SecretKeySpec(secret, "AES");
c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
CipherInputStream cis = new CipherInputStream(new FileInputStream(f), c);
BufferedReader br = new BufferedReader(new InputStreamReader(cis)); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用busybox"nice"和"renice"来调整Android进程优先级,但我不知道它们是否生效.我尝试在adb shell中使用'ps'和'busybox top',但那些不显示优先级.有没有办法在adb中查看和调整优先级?
c++ ×4
bash ×3
linux ×3
android ×2
android-ndk ×2
c ×2
python ×2
stl ×2
aes ×1
cryptography ×1
encryption ×1
git ×1
java ×1
networking ×1
reentrancy ×1
valgrind ×1