0

I ran a C program with an infinite while loop in a terminal and observed one of the CPU cores shot to 100% usage. When I turn it into a background process using Ctrl+z, the CPU usage suddenly dipped to < 10%. Using htop, I found that the process was using 0% of the CPU. What has happened to the process?

The program

int main() { int i; while( 1 ) { } return 0; } 

Since there is no I/O involved in the program, I made small changes to the program to see if the I/O wait increased the usage, but got the same results (0% usage).

int main() { int i; while( i+1 ) // wait to retrieve i { i = 1; } return 0; } 

What has happened to the process ? Is it running?

1 Answer 1

1

When you press Ctrl+z in your terminal, a SIGTSTP is sent to the process group of the task running in the foreground.

The default action of SIGSTP is to stop (i.e. suspend) the process:

 18 SIGTSTP stop process stop signal generated from keyboard 

If you want the process to resume operation in the background, you can use the shell-builtin bg (short for background). If you want the process to resume operation in the foreground, you can use the fg command.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.