Ref.

http://stackoverflow.com/questions/8166415/how-to-get-the-pid-of-a-process-in-linux-in-c

http://stackoverflow.com/questions/15692275/how-to-kill-a-process-tree-programmatically-on-linux-using-c

http://fanqiang.chinaunix.net/a4/b8/20010811/0905001105_b.html

http://www.cppblog.com/prayer/archive/2009/05/05/81955.aspx

============================================

****Get another process pid :

char len[64];

FILE *cmd = popen("busybox pidof ts_calibrate", "r");

fgets(line, 64, cmd);

pid_t pid=strtoul(line, NULL, 10);

pclose(pid);

****kill process

kill(pid, SIGTERM);

sleep(2);

kill(pid, SIGKILL)

****system call

char cmd[64];

sprintf(cmd, "ls /system/bin");

system(cmd);

****sleep

#include <unistd.h>

sleep(1);  // 1 sec

****thread

/* example.c*/
#include <stdio.h>
#include <pthread.h>
void thread(void)
{
int i;
for(i=0;i<3;i++)
printf("This is a pthread.\n");
}

int main(void)
{
pthread_t id;
int i,ret;
ret=pthread_create(&id,NULL,(void *) thread,NULL);
if(ret!=0){
printf ("Create pthread error!\n");
exit (1);
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 M 的頭像
    M

    M的部落格

    M 發表在 痞客邦 留言(0) 人氣()