void main(int argc, char** argv) { char task_name[50]; pid_t pid = getpid(); printf("pid of this process:%d\n", pid); getNameByPid(pid, task_name); /* strcpy(task_name, argv[0]+2); printf("task name is %s\n", task_name); getPidByName(task_name); */ printf("task name is %s\n", task_name); getPidByName(task_name); sleep(15); }
int main(void) { char task_name[50]; pid_t pid = getpid(); printf("pid of this process:%d\n", pid); void getNameByPid(pid_t pid, char *task_name); getNameByPid(pid, task_name); printf("getNameByPid:%s\n", task_name); void getPidByName(pid_t *pid, char *task_name); getPidByName(&pid, task_name); printf("getPidByName:%d\n", pid); //sleep(15); return 0; }