Re: Changing the state of a process

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

 





Jan Hudec <bulb@xxxxxx> wrote:
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

Thanks Jan for the informative reply.
Actually, I saw the definition of "struct task_struct" in the file include/linux/sched.h for the different states of the process. There it was -1 for unrunnable etc..
 
struct task_struct {
         volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
         struct thread_info *thread_info;
         atomic_t usage;
         unsigned long flags;    /* per process flags, defined below */
         unsigned long ptrace;
 
Can you please throw some light on how the kernel reacts when I try to change the state of the parent process, ie not my own state..? Because I do not see any error thrown up. How does kernel detect this ?
Also I understand that bash shell is in TASK_INTERRUPTIBLE state, because it is waiting for insmod to complete. If possible, pls tell me how it is waken up by SIGCHLD signal when insmod completes.
 
Thanks,
Rajaram. 
 


Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

[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