This question does not make sense.
Do you write kernel-based code? In this case, you can get the pid of the current task using the "current" macro, which points to the current task struct task (which contains the element with pid). This will only work if your kernel code is run in a context where the "current task" makes sense (i.e., not interruption, tasket, etc.).
If you are writing user space code, there should be no reason why you cannot call getpid, which is a library call from the C library defined in unistd.h (or something that it includes) that makes a system call. If there is such a reason, please explain it.
Making a system call on Linux is not particularly difficult, but includes architecture-specific code that you do not want to write.
Markr source share