社区
Linux/Unix社区
帖子详情
为什么以下代码不能调用find_task_by_id
kes2000
2007-08-26 10:17:03
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
void execname() {
struct task_struct *my;
my = find_task_by_id(getpid());
printf("%s",my->comm);
}
int main() {
execname();
return 0;
}
...全文
109
1
打赏
收藏
为什么以下代码不能调用find_task_by_id
#include #include #include void execname() { struct task_struct *my; my = find_task_by_id(getpid()); printf("%s",my->comm); } int main() { execname(); return 0; }
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
cceczjxy
2007-08-26
打赏
举报
回复
find_task_by_id
是个内核函数,你在用户空间没法调用.你不能这样直接使用它.
下边是别人写的,可以看看
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/proc_fs.h>
#include<linux/init.h>
#include<linux/sched.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("scutan");
static int find_read(char *buffer, char **buffer_location, off_t offset, int count, int *eof, void *data)
{
struct task_struct *p;
int pid;
pid = current->pid;
p = find_task_by_pid(pid);
sprintf(buffer, "%d\t%s\n", p->pid, p->comm);
return strlen(buffer);
}
static int __init find_init(void)
{
struct proc_dir_entry *entry;
entry = create_proc_entry("findpid", 0644, NULL);
if (entry == 0)
{
printk(KERN_ERR "creat_proc_entry failed\n");
return -1;
}
entry->mode = S_IFREG | S_IRUGO;
entry->size = 100;
entry->owner = THIS_MODULE;
entry->uid = 0;
entry->gid = 0;
entry->read_proc = find_read;
return 0;
}
void __exit find_exit(void)
{
remove_proc_entry("findpid", &proc_root);
}
module_init(find_init);
module_exit(find_exit);
Makefile
代码:
obj-m:=find.o
KERNELDIR:=/usr/src/linux
default:
make -C $(KERNELDIR) M=$(shell pwd) modules
install:
insmod find.ko
uninstall:
rmmod find.ko
clean:
rm -rf *.o *.mod.c *.ko
另外还有一个测试程序get.c
代码:
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<fcntl.h>
#include<unistd.h>
int main()
{
int fd;
char buf[50];
fd = open("/proc/findpid", O_RDONLY);
if (fd < 0)
{
printf("error\n");
exit(1);
}
memset(buf, 0, sizeof(buf));
if (read(fd, buf, 50) < 0)
{
printf("read error\n");
exit(1);
}
printf("buf = %s\n", buf);
printf("getpid = %d\n", getpid());
return 0;
}
Linux CFS调度器之pick_next_
task
函数
Linux CFS调度器之pick_next_
task
函数流程简介
【内核调度、负载均衡】【select_
task
_rq_fair】
在新建一个
task
或者block的
task
被唤醒的时候,也会执行负载均衡,
调用
的函数是select_
task
_rq_fair 和内核周期性调度相似(寻找最忙的cpu上的任务,然后把该任务pull过来执行。或者从最忙的cpu上将当时正在执行的...
Linux进程管理之通过p
id
号找到struct
task
_struct
Linux 内核态通过p
id
号找到struct
task
_struct的简介
Rails宝典之第二式: 动态find_by方法
Rails宝典之第二式: 动态find_by方法 忘了声明了,这个系列主要是Rails入门教学。 今天Rails宝典教大家的是动态find_by方法,我们先看一段
代码
: Ruby
代码
class
Task
sController ...
find_element
调用
报错NoSuchElementError: An element could not be located on the page using the given sear
出现的原因是第7行a.find_element(By.
ID
, 'im2510.hollcon.com.im2510:
id
/edit_account').send_keys("admin")中By.
ID
后面应该用双引号,用了单引号就报错了,改成双引号就能正常运行了,为什么用单引号这里报错还...
Linux/Unix社区
23,121
社区成员
74,508
社区内容
发帖
与我相关
我的任务
Linux/Unix社区
Linux/Unix社区 应用程序开发区
复制链接
扫一扫
分享
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章