Re: Changing the state of a process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 22, 2005 at 22:41:48 -0800, Rajaram Suryanarayanan wrote:
>  Hi,
>  
>  I wrote a simple kernel module to play with the process descriptor structure of a process. I have given the code below.
>  
>  int init_module(void)
>  {
>  
>   printk(KERN_INFO "Hello Process \n");
>   printk(KERN_INFO "Parent process ID :%d \n",current->parent->pid);
>   printk(KERN_INFO "Parent process state :%d \n",current->parent->state);
>   printk(KERN_INFO "Parent process uid :%d \n",current->parent->uid);
>   printk(KERN_INFO "Parent process priority :%d \n",current->parent->prio);
>  
>   /* Change the parent process state to unrannable */
>   current->parent->state= -1;
>   return 0;
>  
>  }
>  
>  By this code, I am trying to print the details of the parent process of
>  the current process ( current process is insmod and its parent process is
>  the bash shell from which I issued insmod command, if I am not wrong ).

Yes, you are right.

>  Also I try to change the state of the bash shell to -1 ( unrunnable ).

I see it in the comment, but that state does not seem to actually exist.

>  I see that the current->parent->state is printed as 1 . I see that process
>  state > 0 is stopped , as defined in "struct task_struct". Then why it is
>  printed as 1 when the bash shell is actually running ?

No, it's not actually running. It's waiting for it's child to exit or be
stopped, inside wait syscall. State 1 is TASK_INTERRUPTIBLE.

>  Also by changing the state of the bash shell to -1, I expected it to hang
>  or something like that. But that did not happen. 
>
>  Could anyone please let me know what is wrong with my approach..?

Don't use the numbers. Use the symbolic values TASK_RUNNING,
TASK_INTERRUPTIBLE, TASK_UNINTERRUPTIBLE and so on.

However, that's not the major problem. The major problem is, that it's only
permitted to alter your own state (that is set_current_state) except
well-defined case of waking up a process on a wait-queue.

-- 
						 Jan 'Bulb' Hudec <bulb@xxxxxx>

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux