A Kernel Thread Shares The Open Files From A User Thread

Hi all,

In my work, I'd like to spawn separate kernel threads (tasks) to execute syscall asynchronously. Specifically, a user thread issues a syscall, goes into kernel, save the syscall number and arguments somewhere in the kernel address space, but does not execute the syscall. A kernel thread which is different from the user thread, will fetch the syscall number and arguments to execute the syscall on behalf of the user thread.
But for file operations such as read, the kernel thread is not aware of the open files of the user threads. For example, if the user thread opens a file and get a file descriptor, then it issue a read() syscall. The kernel thread cannot execute the read() on behalf of the user thread by just using the file descriptor. Thus I need some way to allow the kernel thread share the open files information with the user thread, such that the kernel thread will have the context of the open file to execute read(). I tried to pass the files_struct of the user thread's task_struct to the kernel thread, but it didn't help, read() returns a EFAULT error.
Can anyone give me some suggestions on how to make a kernel thread share the open files with a user thread? Or more straightforward how to execute the read() syscall in the example above in kernel thread? Thank you very much!

--Louis


Similar Content



Is It Time For A Modem Funeral?

I have a USB fax modem, and it logs the following errors when turned on.

I know it is impossible to know for sure, but think it is hardware related? Any chance to salvage?

Also, what are the steps to start troubleshooting?

Thanks

Code:
Jan 17 14:38:26 devserver kernel: generic-usb 0003:0461:4D0F.0066: input,hidraw2: USB HID v1.11 Mouse [PixArt USB Optical Mouse] on usb-0000:00:1a.0-1.2/input0
Jan 17 14:38:41 devserver kernel: usb 3-1: new full speed USB device number 24 using xhci_hcd
Jan 17 14:38:41 devserver kernel: usb 3-1: device descriptor read/all, error -71
Jan 17 14:38:41 devserver kernel: usb 3-1: new full speed USB device number 25 using xhci_hcd
Jan 17 14:38:41 devserver kernel: usb 3-1: device descriptor read/all, error -71
Jan 17 14:38:41 devserver kernel: usb 3-1: new full speed USB device number 26 using xhci_hcd
Jan 17 14:38:41 devserver kernel: usb 3-1: device descriptor read/8, error -71
Jan 17 14:38:41 devserver kernel: usb 3-1: device descriptor read/8, error -71
Jan 17 14:38:41 devserver kernel: usb 3-1: new full speed USB device number 27 using xhci_hcd
Jan 17 14:38:41 devserver kernel: usb 3-1: device descriptor read/8, error -71
Jan 17 14:38:42 devserver kernel: usb 3-1: device descriptor read/8, error -71
Jan 17 14:38:42 devserver kernel: hub 3-0:1.0: unable to enumerate USB device on port 1

Communication Between User Space And Kernel Module

hi
I have two code of user.c and kernel.c , i have compiled new kernel in my system , but i don't know how to compile these code.
may i use any IDE or GCC.

What Is Context Switching

I'm currently reading Brian Wards book: How Linux Works: What Every Superuser Should Know 2nd edition and I'm confused about step 3 in the context of the other steps:
1. The CPU (the actual hardware) interrupts the current process based on an internal timer, switches into kernel mode, and hands control back to the kernel.

2. The kernel records the current state of the CPU and memory, which will be essential to resuming the process that was just interrupted.

3. The kernel performs any tasks that might have come up during the preceding time slice (such as collecting data from input and output, or I/O, operations).

4. The kernel is now ready to let another process run. The kernel analyzes the list of processes that are ready to run and chooses one.

5. The kernel prepares the memory for this new process, and then prepares the CPU.

6. The kernel tells the CPU how long the time slice for the new process will last.

7. The kernel switches the CPU into user mode and hands control of the CPU to the process.

What does he mean preceding time slice as surely the tasks have been completed during the time slice in steps 1-2?

Kill Zombie Process Via C Program Without Killing Main Process

Hi ,
In my program, for a process A executing operation, there are multiple threads created.
One of the thread A checks whether process is active or not
Second thread B executes a function
One of the periodic thread C calls a callback function that executes an audit after every 30 secs.

In the audit , the function uses g_spawn_commmand_line_sync() function to spawn a child process that executes a command line (shell script).

Since g_spawn_commmand_line_sync() spawns a new child process .
In the error case scenario, the spawned child process got stuck and became zombie process. It did not get killed.Also it acquired sockets which were assigned to a thread B executing operation.

Even though the thread B got terminated ,the child process did not release the sockets that were connected to it.


My question is ,I have to automate this in C program that if it finds spawned process of g_spawn_commmand_line_sync() defunct, the
health check thread B should be able to clean it without klling the main process.

i could not find any spawn function that will help me find the PID of g_spawn_commmand_line_sync() spawned process.

I get the details from ps commands. But how can I find it in a c-program?

What Does Kernel Refer To Load Modules At Boot Time/

lsmod is command to list loaded modules and I referred man page of lsmod that shows it refers to /proc/modules file. In terms of my os platform, Ubuntu, almost available modules are in /lib/module directory. I think OS kernel naturally loads modules in there. So, What does kernel refer to load modules at boot time?

Is there any files to be refereed for loading or mechanism can't know easily for end user?

Kernel V4

Hi guys prob a silly question...
i only just read now that linux kernel v4 was released about 11 days ago...can any distros upgrade there kernel to 4 or only specific ones?

Is there really a huge benefit in doing so?

should i just lookup the information in the distros web site?

Difference In Output When Using Pthread_join??

For the below code, I observe that when pthread_join is commented from the code - the order of thread execution is not consistent (the main thread executes first and then the remaining threads - in what sequence I am not sure). But when pthread_join is present in the code - I see that order of execution of the threads is as per the code (First t1, then t2 and finally main exits....I can tell that for sure by observing the increasing value of id in main())

Can anybody tell me why that happens?


#include <pthread.h>
#include <stdio.h>
pthread_once_t once = PTHREAD_ONCE_INIT;

void *myinit()
{
printf("\n I am in init\n");
}

void* t1routine(void* i)
{
printf("\n I am in thread%d\n", *(int*)i);
pthread_once(&once, (void*)myinit);
printf("\n I am exiting from thread %d\n", *(int*)i);
}

void* t2routine(void* i)
{
printf("\n I am in thread%d\n", *(int*)i);
pthread_once(&once, (void*)myinit);
printf("\n I am exiting from thread %d\n", *(int*)i);
}

void* t3routine(void* i)
{
printf("\n I am in thread%d\n", *(int*)i);
pthread_once(&once, (void*)myinit);
printf("\n I am exiting from thread %d\n", *(int*)i);
}

main()
{
int id = 1;
pthread_t t1,t2,t3;
pthread_create(&t1, NULL, t1routine, (void*) &id);
pthread_join(t1, NULL);
id++;

pthread_create(&t2, NULL, t2routine, (void*) &id);
pthread_join(t2, NULL);
id++;

pthread_create(&t3, NULL, t3routine, (void*) &id);
pthread_join(t3, NULL);
pthread_exit(NULL);
}

Preempt_rt Install Over Ubuntu 14.04

Hi everyone (i hope this is the right section)

Im trying to install the RT patch preempt_rt 3.18.9 im running Ubuntu 14.04 with kernel v 3.16

i installed the rt patch "patch-3.18.9-rt5.patch" and also a new kernel "3.18.9" i patched the patch file with

patch -p1 < patch-3.18.9.patch

but there is somthing i don't know about linking folders of old kernel and new kernel, i searched about it and found

rm -rf linux && ln -s /usr/src/linux-3.18.9 linux && cd /usr/src/linux

then

make oldconfig

then

make menuconfig

i selected Full preemptive kernel then

make

then this error

cc1: some warnings being treated as errors make[2]: * [kernel/locking/locktorture.o] Error 1 make[1]: * [kernel/locking] Error 2 make: *** [kernel] Error 2


So..... Any help?? can someone walk me through this

or any other real time patch, Thanx.. plzzzzzz

Watching / Capturing An Applications Threads

There is a home grown application that initiates either a telnet or ssh session based on the number of threads set.

I want to watch the process happen from start to finish, that is from the moment the first thread starts until the last thread finishes.

I was thinking netstat, but it wont show the process in its entirety. As connections are established and terminated the status / output of the command would be different..not to mention Id have to keep hitting the command and the enter key.

As usual, I have cracked my Linux in a nutshell book and will be doing web searches to find a solution.

Need Kernel Header File

Hi folks,

I'm trying to install the drivers for my "legacy" nvidia graphics card.
I've downloaded the file from nvidia's website to install the driver, but during the process I get this message...

Kernel header file ' /lib/modules/3.13.0-37-generic/build/include/linux/version.h ' does not exist .

The most likely reason is the kernel source files in ' /lib/modules/3.13.0-37-generic/build ' have not been configured.

Anyone know how to configure this file? I've been working on this for a few days now...it's getting old!

Thanks for your help.

Joe