Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a C program in linux get a PID?

Tags:

c

linux

process

I have a simple C program and when I compile and run it with ./output, does it get a PID on Linux? (I think, every running program is a process and it should have a PID.)

I used the ps aux command but I couldn't find the process name there.

I remember, when my console application (a C program) was running on Windows 7, I was able to get its PID via the Volatility tool.

#include<stdio.h>

void main()
{
    printf("Hello World!");
}
like image 203
Junaid Avatar asked Dec 08 '22 20:12

Junaid


2 Answers

Yes, every running program on Linux gets a PID.

Your program just prints "Hello, World!", and will complete so quickly that by the time you run ps aux it will have finished.

Also, void main() should be int main(void), and you should add \n to the end of your output string.

like image 62
Keith Thompson Avatar answered Dec 20 '22 08:12

Keith Thompson


It should. just printf getpid() in you program to see it.

like image 31
rahul Avatar answered Dec 20 '22 08:12

rahul