ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to know if there's a way to get the pid of a process by using it's name. Also, how can I know of the processes that are running and their pids?
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Calling a shell script from a C program instead of using the C APIs defeats some or all of the interest of writing a C program vs a shell script.
Also, if you still want to use pidof instead of what I sent you (pgrep C source code), you'd rather use popen() instead of system() to get pidof output.
I did look at the pgrep.c file...but i'm araid i don't know hw to include it in my code..i'm actualy modifying iptables kernel code, where I need to find the pid of another process. I found it easier to write just one line in the existing code rather than having to paste the source code of pgrep.c. i'm using RH9 by the way.
Can you suggest me a way of how to use prep.c while causing minimal intrusion in the existing iptables kernel code? I can't use makefiles..
I did look at the pgrep.c file...but i'm araid i don't know hw to include it in my code..i'm actualy modifying iptables kernel code, where I need to find the pid of another process. I found it easier to write just one line in the existing code rather than having to paste the source code of pgrep.c. i'm using RH9 by the way.
Can you suggest me a way of how to use prep.c while causing minimal intrusion in the existing iptables kernel code? I can't use makefiles..
Also, can you tell me why you suggest the use of popen(). CAn you give me an example of how to use it?
I'm trying to call a .c program (Prog1.c) from another .c program (Prog2.c). Prog1.c is actually part of the iptables kernel code. I'm only modifying the file. I'll need to recompile the kernel. Prog2.c is a userspace program that i will write entirely. Prog1.c will send a signal to Prog2.c every time a packet passes through the code of Prog1.c. But in order to send the signal to Prog2.c, Prog1.c needs to know the pid of Prog2.c and then send it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.