Reference no: EM13518212
Print some information of all the processes pointed by init_task, something similiar to "ps -ef", including UID, PID, PPID, thread name, etc.
Create five kernel threads using the following methods:
Create 2 threads using kernel_thread()
Create 3 threads using kthread_create()
Print some information of all the processes including the five threads. The output will be part of dmesg or messages. Try to follow the "ps -ef" format when printing all the processes including your own threads.
See the sample output below that shows the process list and the boot time messages.
Example: process list ("$ps -ef")
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 09:36 ? 00:00:00 /sbin/init
root 2 0 0 09:36 ? 00:00:00 [kthreadd]
root 3 2 0 09:36 ? 00:00:00 [ksoftirqd/0]
root 4 2 0 09:36 ? 00:00:00 [migration/0]
root 5 2 0 09:36 ? 00:00:00 [watchdog/0]
root 6 2 0 09:36 ? 00:00:00 [events/0]
root 7 2 0 09:36 ? 00:00:00 [khelper]
root 10 2 0 09:36 ? 00:00:00 [kstop/0]
root 145 2 0 09:36 ? 00:00:00 [kintegrityd/0]
root 147 2 0 09:36 ? 00:00:00 [kblockd/0]
...
root 579 2 0 09:36 ? 00:00:00 [hid_compat]
root 612 1 0 09:36 ? 00:00:00 [My name:my_d]
root 613 1 0 09:36 ? 00:00:00 [My name:my_d]
root 614 2 0 09:36 ? 00:00:00 [my_kernel_threa]
root 615 2 0 09:36 ? 00:00:00 [my_kernel_threa]
root 616 2 0 09:36 ? 00:00:00 [my_kernel_threa]
root 632 2 0 09:37 ? 00:00:00 [kjournald]
root 681 1 0 09:37 ? 00:00:00 /sbin/udevd -d
...
For creating the first 2 threads try the following procedure:
Declare the functions that will create threads and those threads that will actually do something:
static void my_kernel_thread_create_1(void);
static void my_kernel_thread_create_2(void);
...
static void my_kernel_thread_create_1(void){
int mypid;
printk(KERN_NOTICE "My name: Calling kernel_thread(m_k_t_do_something_1)n");
mypid = kernel_thread(m_k_t_do_something_1, NULL, CLONE_KERNEL);
printk(KERN_NOTICE "My name: m_k_t_do_something_1 = %dn", mypid);
}
static void my_kernel_thread_create_2(void){
int mypid;
printk(KERN_NOTICE "My name: Calling kernel_thread(m_k_t_do_something_2)n");
mypid = kernel_thread(m_k_t_do_something_2, NULL, CLONE_KERNEL);
printk(KERN_NOTICE "My name: m_k_t_do_something_2 = %dn", mypid);
}
...
static void m_k_t_do_something_1(void){
struct task_struct *curtask = current;
strcpy(curtask->comm, "My name: m_k_t_do_something_1");
set_task_state(curtask, TASK_RUNNING);
printk(KERN_NOTICE "My name: m_k_t_do_something_1 is about to be scheduled.n");
schedule();
printk(KERN_NOTICE "My name: m_k_t_do_something_1 is now scheduled.n");
}
static void m_k_t_do_something_2(void){
struct task_struct *curtask = current;
strcpy(curtask->comm, "My name: m_k_t_do_something_2");
set_task_state(curtask, TASK_RUNNING);
printk(KERN_NOTICE "My name: m_k_t_do_something_2 is about to be scheduled.n");
schedule();
printk(KERN_NOTICE "My name: m_k_t_do_something_2 is now scheduled.n");
}
...
Call those functions that will create these threads.
...
print some info on all the processes on runqueue;
...
printk(KERN_NOTICE "My name: m_k_t_do_something threads are about to be created.n");
my_kernel_thread_create_1();
my_kernel_thread_create_2();
...
printk(KERN_NOTICE "My name: m_k_t_do_something threads are created.n");
...
print some info on all the processes on runqueue;
...
run_init_process("/sbin/init");
...
Remember to print process info before you call these functions, after you calll the functions, and after terminate
For creating the last 3 threads try the following procedure:
Declare the functions that create threads and those threads that actually do something like the above.
Use kthread_create() to create kernel threads. kthread_create() adds the newly created kernel thread to the global list kthread_create_list, as we discussed in class.
See apm_init() as an example.
static int __init apm_init(void){
...
kapmd_task = kthread_create(apm, NULL, "kapmd");
...
}
For printing some info on processes, try the following:
...
struct task_struct *tmp_tsk;
...
tmp_tsk = current;
for_each_process(tmp_tsk) {
...
print some info on all the processes on runqueue;
...
}
Now, remove all the threads you created and print all the processes, something similiar to "ps -ef".
The network administrator of lenix ventures
: The network administrator of Lenix Ventures
|
Identify the troublesome computer''s ip address and host
: What commands would you use to identify the troublesome computer's ip address and host name?
|
Write a small program in java that builds routing tables
: Write a small program in Java that builds routing tables for nodes based on shortest path routing using dijkstras algorithm. Where path distance is measured by edges. The input for this problem is the connectivity information for all the nodes..
|
Personal trainer
: PERSONAL TRAINER, INC.
|
Information of all the processes pointed by init
: Print some information of all the processes pointed by init_task, something similiar to "ps -ef", including UID, PID, PPID, thread name, etc.
|
Linear programming problem using branch and bound
: Solve this linear programming problem using Branch and Bound
|
Research the key terms
: Research the key terms
|
Describe the state of nuclear energy
: Based on current events, describe the state of nuclear energy and its peaceful uses in at least one country.In your opinion, which is the greater threat
|
What is the basis of kantianism
: What is the basis of Kantianism? You have Machiavellianism, Grotianism and Kantianism. What is the primary way in which Kantianism differs from the other two?
|