LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2013, 07:07 AM   #1
ShankyV
LQ Newbie
 
Registered: Apr 2013
Posts: 1

Rep: Reputation: Disabled
How to schedule multiple infinitely running processes in linux, in C


Hi Everyone,
I need a way to schedule multiple (to be precise three different processes) infinitely running processes that I am creating to be scheduled initially and then later they may run in parallel fashion.
The code is something like this:

int main()
{
fork() //forking the main process
if (parent)
//will invoke the signal handler for Ctrl+C, for killing all childs
if (child)
{
fork() //fork again
if(parent1)
// run 1st infinite process
else // if child1
fork() //fork again
if(parent2)
//run 2nd infinite process
else //when child2
//run 3rd infinite process
}
}

I need process1 to start first and then process2 should get started and then process3. Later they may run parallel !
 
Old 04-15-2013, 02:38 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
and what has been done so far? Do you have any problem?
 
Old 04-15-2013, 09:13 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The more common idiom is to exec other programs from the child process after a fork. This gives the parent process the ability to wait() on the child, so the process table doesn't get cluttered with zombies.
--- rod.
 
Old 04-16-2013, 06:24 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Not to be flippant here, but what if you simply write a shell-script that uses the '&' suffix to launch the three processes? Possibly with nohup? They won't be children of the parent process and you might have to prevent multiple-copies, but it would be "the shortest way to get there."
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Software Design For Embedded Linux System with Multiple Asynchronous Processes D1ver Programming 3 09-22-2012 04:51 PM
[SOLVED] Why are multiple processes running with the same command - htop in Debian Squeeze gacanepa Linux - Newbie 2 09-19-2012 10:38 AM
Expect: Restrictions on spawning multiple processes on Linux-Fedora rajivk Programming 0 02-05-2012 05:22 PM
are all processes running in linux required shyam_d_sundar Linux - Newbie 3 03-08-2004 01:03 PM
HTTPD running multiple processes jjustin01 Linux - Software 1 03-04-2004 07:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration