#include<stdio.h>
#include<conio.h>
void hello()
{ printf("\nHELLO\n");
}
int main()
{
hello();
hello();
hello();
hello();
getch();
return 0; 
}

If I run this code on a compiler,how many processes and how many threads will be running on the compiler and which ones?
Does a duplicate function call consist another process or thread?
Does a main() function have any process associated with it?

Dani AI

Generated

was on the right track. The compiler only produces an executable; when you run that executable the operating system creates one process for it. That process starts with a single thread (the “main” thread) which begins execution at main(). Repeated or duplicate function calls do not spawn new processes or threads — they just push new stack frames onto the same thread’s call stack.

Why that matters: a function call is a synchronous transfer of control inside the current thread. Each call creates a stack frame (locals, return address) and returns to the caller when done. To get parallel execution you must explicitly create threads or processes (for example, pthread_create / std::thread on POSIX/C++ or CreateThread / CreateProcess on Windows). Example (POSIX threads):

#include <pthread.h>
#include <stdio.h>

void* worker(void* arg){ puts("worker"); return NULL; }

int main(){
    pthread_t t;
    pthread_create(&t, NULL, worker, NULL);
    pthread_join(t, NULL);
    return 0;
}

How to check what’s actually running: on Linux use ps -L -p <pid>, top -H -p <pid>, or ls /proc/<pid>/task to list threads. On Windows use PowerShell: Get-Process -Id <pid> | Select Id,ThreadCount or Sysinternals Process Explorer to inspect threads inside a process. Note that IDEs, debuggers, language runtimes or certain library calls can create background threads, and tools (antivirus, profilers) may add processes — so a simple program usually shows one process and one thread, but the environment can add more.

Recommended Answers

All 5 Replies

Number one, The code doesn't run in a compiler. The code is compiled by the compiler so that it can run within an operating system environment.

How many threads? Just one, the main thread.

Number one, The code doesn't run in a compiler. The code is compiled by the compiler so that it can run within an operating system environment.

How many threads? Just one.

Thanks.....
Yes,I know compiler only compiles the code.

And what about processes?


And what about processes?

What about them?

What about them?[

How many processes will run ?
And which ones?

What about them?[

How many processes will run ?
And which ones?

I told you, in the code you posted, only one thread is running.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.