Re: stopping a process temporarily

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

 



Hello,

>    You can do this by just having the task_struct for
> the task you want to make to sleep.  
> 
> You can use the macros predefined in linux/sched.h
> like set_task_state(....)  or set_current_state(..) by
> the different states in the same file.   Set the state
> to TASK_INTERRUPTIBLE, etc.Call schedule() after that.

Sorry, but that won't work. set_current_state is for
the current process only - which is not true in this case.

Also TASK_INTERRUPTIBLE (nor UNINTERRUPTIBLE) state probably
won't be much help. TASK_STOPPED could be forcibly set (as
SIGSTOP handling does), and probably it will work, except I
am not sure if there won't be problem with processes in
UNINTERRUPTIBLE state. These may expect not to be awoken
before the condition they wait on is true (which may happen
if they are forcibly stopped and then continued), though
such an expectation is definitely a bug.

So try stoping the process by
set_task_state(task, TASK_STOPPED)
(consider if you should notify parent with SIGCHLD via
notify_parent(task, SIGCHLD)).

To wake it up use wake_up_process. Using SIGCONT would
be seen by tracing process.

> You can even use interruptible_sleep_on(..) for making
> the process sleep.

That's for current only - that's not the case here.

> To find out the task_struct, use the function
> find_task_by_pid(..).
> 
> You can easily do this.  This has worked out in my
> code.
> > I need to stop a process temporarily from the
> > context of a different process.
> > 
> > I can't send it SIGKILL, I need to stop it
> > _temporarily_. 
> > I can't send it SIGSTOP (I think); if the process is
> > being ptrace'd the parent
> > will get control, not what we want.
> > 
> > I suspect we should be able to achieve this by
> > fiddling with task->state bits
> > but not sure, especially considering that the target
> > process could be in
> > any state (running/blocked/readytorun ...) when we
> > want to do this.

--------------------------------------------------------------------------------
                  				- Jan Hudec `Bulb' <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[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