Sponsored Content
Full Discussion: fork()ing hell!!
Top Forums Programming fork()ing hell!! Post 14828 by jj1814 on Thursday 7th of February 2002 12:17:55 AM
Old 02-07-2002
Quote:
Originally posted by Perderabo
Your post helped me out with a fork I am writing, but I am having a little trouble because the execve command only executes the "ls" command when i type one in - no matter WHAT command I type in. if i modify execve("/bin/ls", .....) to only read execve("/bin/", .....), it doesnt execute ANYTHING. what do i need to do? Here is my code:
Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream.h>
#include <string>
#include <iomanip.h>
#include <sys/wait.h>

main()
 {
  cout<<"You have entered my 1814 shell"<<endl;
//  string command;
  char line[1024], *doit[20];
  int n, pid, parentpid, childpids[0];


  while (line !="exit")
      {

        cout<<"GIMME:#";
        cin.getline(line,sizeof(line));
        cout<<"The command you typed was: " <<line<<endl;
        if (strcmp(line,"exit")==0)
           return 0;

        parentpid=getpid();
        printf("I am the parent process and my pid is %d\n", getpid());
        if (pid=fork())
          {
             int status;
             waitpid(-1, &status, 0);
             childpids[n]=pid;
          }
                  else
          {
             printf("I am a child process and my pid is %d\n", getpid());
             doit[0] = "ls";
             doit[1] = "-la";
             doit[2] = NULL;
             execve("/bin/ls", doit, NULL);
             exit(0);
          }
      printf("I am still the parent process and my pid is %d\n",
         getpid());
   }//end of while
 if (line =="exit")
 return 0;

printf("I am still the parent process and my pid is %d\n", getpid());
}//end of main


Last edited by jj1814; 02-07-2002 at 01:06 PM..
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

rpm hell!

I've just installed redhat 6.2 on one of my systems and am trying to install the gcc c compiler after downloading an rpm from the redhat site. The damn thing gives me: only major numbers <= 3 are supported by this version of RPM what do I do, it does the same with the latest rpm of php ... (7 Replies)
Discussion started by: knmwt15000
7 Replies

2. Shell Programming and Scripting

hell and sqlite

Hi everyone, I have a requirement that requires me to fill an sqlite database with 100,000 entries (no duplicates). I will start out by giving the command that will insert the values necessary to populate the database: # sqlite /var/local/database/dblist "insert into list... (2 Replies)
Discussion started by: ogoy
2 Replies

3. Shell Programming and Scripting

hell & mathematics

I've been able to generate output based on the code scarfake provided me (thanks again man). A little background so everyone more or less knows whats going on: I needed code that would propagate a database with 100,000 entries, for capacity testing purposes, something like a stress test. ... (5 Replies)
Discussion started by: ogoy
5 Replies

4. UNIX for Dummies Questions & Answers

Confussed as hell

:eek: (1 Reply)
Discussion started by: Kevinfine
1 Replies

5. What is on Your Mind?

The Hell of colaboration in UNIX and Linux

I don't want to speak about the goods or bads of both kinds of Operating systems, I only want to share a little experience with you to comment it. I live in Spain and I have home some old unix systems, some of them that I want to sell or change for other things, like a pair of Sun Blade 2000... (0 Replies)
Discussion started by: Golfonauta
0 Replies

6. Shell Programming and Scripting

grep'ing and sed'ing chunks in bash... need help on speeding up a log parser.

I have a file that is 20 - 80+ MB in size that is a certain type of log file. It logs one of our processes and this process is multi-threaded. Therefore the log file is kind of a mess. Here's an example: The logfile looks like: "DATE TIME - THREAD ID - Details", and a new file is created... (4 Replies)
Discussion started by: elinenbe
4 Replies

7. Shell Programming and Scripting

quoting hell - help needed!!

I am writing a bash script to automate the installation of web environment on a base install of Fedora. And I'm at the limit of my last nerve and my bash skills. My brain is screaming at me: "Give up and use perl", but I am trying to stick to bash since the script will modify the perl environment... (6 Replies)
Discussion started by: lbe
6 Replies

8. Programming

Issue when fork()ing processes

Hi guys! I'll simplify my problem. I have the following code: #include <fcntl.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <signal.h> #include <fcntl.h> #include <unistd.h> #include <sys/wait.h> #define max 25 #define buffdim 50 void p1(); void p2();... (2 Replies)
Discussion started by: pfpietro
2 Replies
isaexec(3C)						   Standard C Library Functions 					       isaexec(3C)

NAME
isaexec - invoke isa-specific executable SYNOPSIS
#include <unistd.h> int isaexec(const char *path, char *const argv[], char *const envp[]); DESCRIPTION
The isaexec() function takes the path specified as path and breaks it into directory and file name components. It enquires from the running system the list of supported instruction set architectures; see isalist(5). The function traverses the list for an executable file in named subdirectories of the original directory. When such a file is located, execve() is invoked with argv[] and envp[]. See exec(2). RETURN VALUES
If no file is located, isaexec() returns ENOENT. Other return values are the same as for execve(). EXAMPLES
Example 1: Example of isaexec() function. On a system whose isalist is sparcv7 sparc the program int main(int argc, char *argv[], char *envp[]) { return (isaexec("/bin/thing", argv, envp)); } will look first for an executable file named /bin/sparcv7/thing, then for an executable file named /bin/sparc/thing. It will invoke execve() on the first executable file it finds named thing. On that same system, a program called /u/bin/tofu can cause either /u/bin/sparcv7/tofu or /u/bin/sparc/tofu to be invoked using the follow- ing code: int main(int argc, char *argv[], char *envp[]) { return (isaexec(getexecname(), argv, envp)); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ SEE ALSO
exec(2), getexecname(3C), attributes(5), isalist(5) SunOS 5.10 20 Mar 1998 isaexec(3C)
All times are GMT -4. The time now is 06:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy