1

I'm currently writting program using signals, and I've got this trouble:

How can I change state of executing program to stopped/running without sending SIGSTOP/SIGCONT?

I understand, that I need to use:

 void add_to_runqueue (struct task_struct * p)

and

void del_from_runqueue (struct task_struct * p)

but how to obtain structure task_struct of currently running process?

Also: if it is all that I need to do (calling those 2 functions).

Thanks in advance!

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Karol
  • 11
  • 1
  • 2

1 Answers1

2

These functions would be kernel functions, i.e. internal to the OS. When you are writing a program, you need to go through the appropriate system calls, in your case kill.

When you have a programs process ID (i.e. its number), you can use

kill(pid, SIGSTOP);

and

kill(pid, SIGCONT);

You should not use SIGTSTP unless you know what you are doing.

Simon Richter
  • 28,572
  • 1
  • 42
  • 64
  • I know :) and sending an signal is not an issue to me. Process also have to stop and continue another processes, so I want to handle those two signals (send by user via console). Simple usage of continue does not satisfy me.. – Karol Jun 07 '11 at 09:19
  • You can't handle SIGSTOP, it is one of the signals that have a fixed meaning. You can handle SIGTSTP by either ignoring it (your program continues), or cleaning up your state and then sending yourself a SIGSTOP. – Simon Richter Jun 07 '11 at 09:58
  • Let me clarify: It is about writting a signal handler not about sendin signals. If user sends a signal to my program, (it is SIGTSTP OR SIGCONT), it is supposed to either stop another 2 processes (which are forked family) and then stop itself or (or continue appropriately). I know well what particular signals do. Question: what function shuld I use, and how to change task_struct.state field to TASK_RUNNING to TASK_STOPPED or TASK_RUNNING to TASK_STOPPED. I've learn a lot reading sched.h, however I'm not an native english user, and there is a lot that i don't know. Sorry for my bad english. – Karol Jun 07 '11 at 13:50
  • 1
    You can send signals to yourself. When handling SIGTSTP, you would stop the child processes via SIGTSTP, and then send SIGSTOP to yourself. For SIGCONT, no special handling is needed for your own process. – Simon Richter Jun 08 '11 at 08:54
  • Is there another way of doing this? As I've said before: signals do not satisfy me. – Karol Jun 08 '11 at 19:17
  • No, the signal interface is the only way. It would have been possible to add more system calls, but in general duplicating functionality for no good reason is frowned upon. – Simon Richter Jun 08 '11 at 20:10