LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 08-22-2011, 02:30 PM   #1
cheranj
LQ Newbie
 
Registered: Aug 2011
Location: India
Posts: 1

Rep: Reputation: Disabled
Windows Spawnl (nowait) like function in Linux... How to use Execl function?


Hi All,

Hope you all are doing great there.
I am familiar with spawn function in Windows, where i will initiate another process and stop there itself?

Windows Code:

error = spawnl(P_WAIT,"C:\\showjpg.exe",

"C:\\showjpg.exe","D:\\6\\2.jpg","-q","-c","-e","-k",NULL );

Similarly i am trying in linux.After googled i found feh image viewer would be good to display image from command line.So i included in my C Program.

Here is the line,

execl("/usr/bin/feh", "/usr/bin/feh","-F","-Z","-x","-dD","-d","-q","/root/Desktop/Study/Vision\ chart/New\ folder/images/01.jpg",NULL);

The problem i am facing here is its getting stopped as the old process was replaced by the new exiting process.My wish was after executing the old process(i.e. after displaying the new image it should return back to the C program itself) so that further i need to display image on getting suitable input from the user.


Can anyone help me to solve this ?? This process should get exited once its executed.I m stucked here.

Many Thanks!!!
Cheran
I m still a learner - As Always
 
Old 09-15-2011, 05:18 PM   #2
fry@lvc.edu
LQ Newbie
 
Registered: Mar 2009
Posts: 1

Rep: Reputation: 0
Hello cheranj.

execl does not create any new process. It just changes the program you're running.

Use fork() to create a new process:

int pid;
if (pid=fork()) {
// Nonzero return means you're parent process
// Variable 'pid' holds child process id number
// Do your parent process stuff here.
// You can wait for child to finish if you wish (with wait())
} else {
// zero return means you are child process
// use execl here to make child run the child program
}

Hope that helps.

Mike Fry, Lebanon Valley College

Last edited by fry@lvc.edu; 09-15-2011 at 05:20 PM.
 
Old 09-15-2011, 09:01 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by fry@lvc.edu View Post
int pid;
if (pid=fork()) {
// Nonzero return means you're parent process
Positive means you're the parent process, but negative is an error. Appropriate suggestion, otherwise.
Kevin Barry
 
  


Reply


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
incompatible implicit declaration of built-in function ‘execl’ ? ? ? jiikka Linux - General 3 05-07-2014 04:09 PM
Passing data from interrupt handler function to tasklet function in kernel programmin double-out Programming 2 05-18-2010 11:10 PM
[SOLVED] Threaded function cannot call a function with extern "C" but nonthreaded function can morty346 Programming 16 01-12-2010 06:00 PM
Compilation issue when Function is parameter in function call on LINUX sa20358 Linux - Software 2 07-24-2008 11:19 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 01:21 PM

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

All times are GMT -5. The time now is 08:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration