Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-18-2008, 06:02 PM   #1
LQ Newbie
Registered: Mar 2008
Location: Nicosia,Cyprus
Posts: 4

Rep: Reputation: 0
Question system calls

Hi there,

i have to do the following task:
i have to great 50 processes, and then with the execlp function to run an other executable. Bellow is the code:

while (N > 0){

pid = fork();

if (pid > 0){ // parent

// do nothing...


else if(pid == 0){ // child

printf("Process %d--CHILD -- PID: %d\n",processNum, getpid());
exec_id = execlp("./computePV2","computePV2" ,"2",(char *)0);



printf("Fork Error\n\n");

computePV2 is the executable. computePV2 takes as an argument the time that the processes have to run. Here "2" is just a parameter to make the program run.

The question is: with what system call and how i ll tell to the process run for 10 seconds and then terminate? and how this time i ll pass it in the execlp function

Thank u for your time

Old 03-19-2008, 07:41 AM   #2
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
sleep(int seconds) is one way to have a process last for ten seconds.

Do you have a requirement to pass a syscall down to the new process, or is the process an independently compiled piece of code? If you fork/exec a new process at first it has all of the functions, etc the parent process had. Write a function that calls sleep, execute it in the new process.
Old 03-19-2008, 06:59 PM   #3
LQ Newbie
Registered: Mar 2008
Location: Nicosia,Cyprus
Posts: 4

Original Poster
Rep: Reputation: 0
to all of you who have read my post, i have finally found the answer. to Jim who was very kind trying to help me i want to state that sleep() susbends the process. what i used is the alarm system call alarm(unsigned int x) where x are the seconds you want to run the process. then i converted the unsigned int x to a string using sprintf since the exec functions takes as parameters strings. well i dont know if it is the best solution, however oit worked which is very important
thank u Aris


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Unix system calls with c pengui Programming 13 07-29-2012 11:54 PM
how does java calls the system calls which are written in c babu198649 Linux - General 3 12-05-2011 03:40 AM
how do you use system calls? slinky2004 General 1 12-22-2005 09:39 PM
Some system calls Spooky Programming 1 11-24-2004 10:17 AM
Number of system calls vladmihaisima Linux - General 2 10-02-2002 02:36 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 PM.

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