Unix/Linux: Handler of SIGCONT/SIGTSTP

2019-09-19 16:56发布

问题:

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!

回答1:

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.