I'm working on a deadlock detection algorithm and I'm only given kernel level libraries, i.e. #include <linux/somelibrary>
and nothing else. Are there kernel-level facilities that will allow me to get the pid of the current process similar to getpid()
of unistd.h
?
This question makes little sense.
Are you writing kernel-based code? In which case you can get the pid of the current task by using the "current" macro which points to the current task's task struct (which contains a member with the pid). That would only work if your kernel code is running in a context where a "current task" makes sense (i.e. not an interrupt, tasklet etc).
If you're writing userspace code, there should be no reason you can't call getpid, which is a library call from the C library defined in unistd.h (or something it includes), which makes the system call. If there is such a reason, please explain it.
Making a system call in Linux isn't particularly difficult, but does involve architecture-specific code that you don't want to write.
Hi,
I did some quick research and I found the answer. Thanks so much for your direction. The quick code I used was:
printf("My current process id/pid is %d\n", current->pid);
Thanks again!