LinuxQuestions.org
Review your favorite Linux distribution.
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-03-2014, 06:18 PM   #1
puntino
Member
 
Registered: Sep 2006
Location: Italy
Distribution: Suse 10.1
Posts: 78

Rep: Reputation: 15
execv Error no display specified


Hello,
I'm trying to launch Firefox with a simple program that use the execv
system call.

Code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   char *argv[] = { "/usr/bin/firefox", 0 };
   execv(argv[0], &argv[0]);
   fprintf(stderr, "Oops!\n");
   return -1;
}
I get the error message:
Error no display specified

By googling, I learnt that the problem is related to the X11 server.
I should open a connection toward this server first.
To address this problem, some people suggest to use -display option.
char *argv[] = { "/usr/bin/firefox -display:=0", 0 };
which doesn't work in my case.

Another option is "system( "/usr/bin/firefox -display:=0").
The program works, but it is not what I want since system spawns the new process and return.

I don't want to create a child process with system. The reason is that the former simplified code will be already the code executed by a child-process.
If I use the system within the child process I get another process
thus the following process tree would be
father process
|->fork child process which executes system( "/usr/bin/firefox -display:=0")
|--> firefox

I want the father process to know the child pid and if it gets started, thus my code is something like:

father process
|->fork child process which executes firefox

father process knows child's pid and if the child started.

Thank you in advance.
Domenico
 
Old 04-03-2014, 08:43 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,387

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by puntino View Post
To address this problem, some people suggest to use -display option.
char *argv[] = { "/usr/bin/firefox -display:=0", 0 };
When you call exec*() directly, the shell isn't there to parse arguments for you, so you need to split them yourself:
Code:
char *argv[] = { "/usr/bin/firefox", "-display:=0", 0 };
 
Old 04-12-2014, 12:34 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,608

Rep: Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105
sg like this
Code:
{"/usr/bin/firefox", "-display", ":0", NULL}
 
Old 04-13-2014, 05:33 AM   #4
puntino
Member
 
Registered: Sep 2006
Location: Italy
Distribution: Suse 10.1
Posts: 78

Original Poster
Rep: Reputation: 15
Guys, thank you!!
Everything is working fine.
 
  


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
execv("/bin/bash") failed system error: No such file or directory bbrian017 Linux - Desktop 1 08-27-2011 02:05 PM
Passing groupadd to execv() returned error msg: "file already locked." walwali Programming 9 11-22-2010 07:36 AM
i have the problem about:execv. sam1201 Programming 10 07-27-2009 12:42 PM
Question about execv() oddabe83 Programming 7 03-06-2008 01:35 PM
Unrecoverable Error: execv() error attempting to run powah Red Hat 0 09-06-2006 02:15 PM

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

All times are GMT -5. The time now is 04:32 AM.

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