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.
When I create a child process that consists of multiple threads, I'll find lots of child processes in the system.
Can you tell me why, or how to solve this problem?
Regards.
Code:
pid_t spawn(const char *program, char *const arg_list[])
{
assert(program && arg_list);
// Duplicate this process.
pid_t children_pid = fork();
if (children_pid != 0) { // This is the parent process.
return children_pid;
} else { // This is the child process
// Now execute PROGRAM
execv(program, arg_list);
// The execvp function returns only if an error occurs
fprintf(stderr, "Error occurred in spawn()'s execvp. "
"[Bad parameter, or Has no root privilege]\n");
abort(); // Abort the child process, no surprise here!
}
}
hello Hko,
I'll accept your advice.
and thank you very much
But my child process has about 100 threads, it's boring to see about 100 child process name in the system after forked.
There's no method to solve this?
Quote:
Originally posted by Hko In Linux, threads are implemented as a special form of processes (lightweight and sharing data).
I think what you see as processes are actually the threads.
May I recommend
Code:
perror("spawn(), execv()");
instead of:
Code:
fprintf(stderr, "Error occurred in spawn()'s execvp. "
"[Bad parameter, or Has no root privilege]\n");
Using perror(), you'll get more specific information in case of an error.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.