* killing a kernel thread. @ 2003-10-17 12:51 Suresh Subramanian 2003-10-17 13:51 ` Richard B. Johnson 0 siblings, 1 reply; 5+ messages in thread From: Suresh Subramanian @ 2003-10-17 12:51 UTC (permalink / raw) To: linux-kernel Hello everybody How do i kill a kernel thread ? Thanks. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: killing a kernel thread. 2003-10-17 12:51 killing a kernel thread Suresh Subramanian @ 2003-10-17 13:51 ` Richard B. Johnson 2003-10-17 15:37 ` David Woodhouse 0 siblings, 1 reply; 5+ messages in thread From: Richard B. Johnson @ 2003-10-17 13:51 UTC (permalink / raw) To: Suresh Subramanian; +Cc: linux-kernel On Fri, 17 Oct 2003, Suresh Subramanian wrote: > Hello everybody > > How do i kill a kernel thread ? > > Thanks. > From: Vladimir Kondratiev <vladimir.kondratiev@intel.com> #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/proc_fs.h> #include <linux/vmalloc.h> #include <asm/uaccess.h> typedef struct kt_priv_struct { int nthreads; /**< let's count how many times kernel_thread succeeded */ int pid; wait_queue_head_t wq; /**< kthread sleep here */ struct completion exited; __u32 volatile status; } kt_priv_t; static kt_priv_t the_data; static int kt_thread(void* arg) { kt_priv_t* priv=(kt_priv_t*)arg; daemonize(); reparent_to_init(); snprintf(current->comm,sizeof(current->comm),"kth_%d",priv->nthreads); ++priv->nthreads; while (!test_bit(0,&priv->status)) { /* framework for periodical execution */ unsigned long to=HZ; /* timeout for periodical maintenance */ do { to=interruptible_sleep_on_timeout(&priv->wq,to); } while ( !signal_pending(current) && to>0 ); if (signal_pending(current)) { spin_lock_irq(¤t->sigmask_lock); flush_signals(current); spin_unlock_irq(¤t->sigmask_lock); } /* thread body - for this simple example do nothing */ } complete_and_exit(&priv->exited,0); } static void kt_start(kt_priv_t* priv) { if (priv->pid>0) return; init_completion(&priv->exited); init_waitqueue_head(&priv->wq); priv->status=0; priv->pid=kernel_thread(kt_thread,priv,0); } static void kt_stop(kt_priv_t* priv) { if (priv->pid>0 && (0==test_and_set_bit(0,&priv->status))) { kill_proc(priv->pid,SIGHUP,1); wait_for_completion(&priv->exited); priv->pid=0; } } static int kt_proc_read(char* buf,char** start,off_t offset,int count,int* eof,void* data) { kt_priv_t* priv=(kt_priv_t*)data; int len=0; len+=sprintf(buf+len,"nthreads = %d\n",priv->nthreads); len+=sprintf(buf+len,"pid = %d\n",priv->pid); *eof=1; return len; } static int kt_proc_write(struct file *file, const char *buffer, unsigned long count, void *data) { char *buf; kt_priv_t* priv=(kt_priv_t*)data; int rc = count; if (count<1) { return -EINVAL; } buf = vmalloc(count+1); if (!buf) return -ENOMEM; buf[count]='\0'; if (copy_from_user(buf,buffer,count)) { rc=-EFAULT; goto out; } switch (buf[0]) { case '+': kt_start(priv); break; case '-': kt_stop(priv); break; } out: vfree(buf); return rc; } static char* kt_proc_name="kthread"; static int kt_mod_init(void) { struct proc_dir_entry *p; kt_priv_t* priv=&the_data; memset(priv,0,sizeof(*priv)); p=create_proc_read_entry(kt_proc_name,0666,NULL,kt_proc_read,priv); if (p) { SET_MODULE_OWNER(p); p->write_proc=kt_proc_write; } return 0; } static void kt_mod_exit(void) { kt_stop(&the_data); remove_proc_entry(kt_proc_name,NULL); } module_init(kt_mod_init); module_exit(kt_mod_exit); MODULE_AUTHOR("Vladimir Kondratiev <vladimir.kondratiev@intel.com>"); MODULE_DESCRIPTION("Kernel thread example"); MODULE_LICENSE("GPL"); Cheers, Dick Johnson Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips). Note 96.31% of all statistics are fiction. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: killing a kernel thread. 2003-10-17 13:51 ` Richard B. Johnson @ 2003-10-17 15:37 ` David Woodhouse 2003-10-17 15:49 ` Richard B. Johnson 0 siblings, 1 reply; 5+ messages in thread From: David Woodhouse @ 2003-10-17 15:37 UTC (permalink / raw) To: root; +Cc: Suresh Subramanian, linux-kernel Ooh ooh RBJcode. I'm going to be fair and only pick one of the errors, leaving many more for others to play the game too... On Fri, 2003-10-17 at 09:51 -0400, Richard B. Johnson wrote: > __u32 volatile status; > while (!test_bit(0,&priv->status)) { test_bit() and friends work on 'unsigned long' not uint32_t. -- dwmw2 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: killing a kernel thread. 2003-10-17 15:37 ` David Woodhouse @ 2003-10-17 15:49 ` Richard B. Johnson 2003-10-17 16:07 ` David Woodhouse 0 siblings, 1 reply; 5+ messages in thread From: Richard B. Johnson @ 2003-10-17 15:49 UTC (permalink / raw) To: David Woodhouse; +Cc: Suresh Subramanian, Linux kernel On Fri, 17 Oct 2003, David Woodhouse wrote: > Ooh ooh RBJcode. I'm going to be fair and only pick one of the errors, > leaving many more for others to play the game too... > > > On Fri, 2003-10-17 at 09:51 -0400, Richard B. Johnson wrote: > > > __u32 volatile status; > > > while (!test_bit(0,&priv->status)) { > > test_bit() and friends work on 'unsigned long' not uint32_t. > > -- > dwmw2 > Well it isn't RBJcode. It's Intel code. Look who wrote it before you give me any credit, especially your kind of "credit". Also, Intel machines have 32-bit longs which are identical to 32-bit ints and this was an Intel driver........ Have fun growing up. Cheers, Dick Johnson Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips). Note 96.31% of all statistics are fiction. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: killing a kernel thread. 2003-10-17 15:49 ` Richard B. Johnson @ 2003-10-17 16:07 ` David Woodhouse 0 siblings, 0 replies; 5+ messages in thread From: David Woodhouse @ 2003-10-17 16:07 UTC (permalink / raw) To: root; +Cc: Suresh Subramanian, Linux kernel On Fri, 2003-10-17 at 11:49 -0400, Richard B. Johnson wrote: > Well it isn't RBJcode. It's Intel code. Look who wrote it > before you give me any credit, especially your kind of "credit". You deserve the same 'credit' for quoting code from a known purveyor of crap code as you'd deserve for writing it yourself. Although to their credit Intel do seem to be capable of writing slightly better code these days than they used to. > Also, Intel machines have 32-bit longs which are identical to > 32-bit ints and this was an Intel driver........ Even some Intel machines have 64-bit longs nowadays. Certainly there's no excuse for that particular error. It's just a gratuitous non-portability. > Have fun growing up. You have to let me have fun -- it's boring just correcting you every time you mislead a newbie. I wouldn't bother if you weren't just picking on people who don't know better, but if you're going to cruelly post utterly broken code in response to a genuine question, someone needs to say something. -- dwmw2 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-10-17 16:07 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-10-17 12:51 killing a kernel thread Suresh Subramanian 2003-10-17 13:51 ` Richard B. Johnson 2003-10-17 15:37 ` David Woodhouse 2003-10-17 15:49 ` Richard B. Johnson 2003-10-17 16:07 ` David Woodhouse
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®