Difference in LINUX and SOLARIS


 
Thread Tools Search this Thread
Top Forums Programming Difference in LINUX and SOLARIS
# 1  
Old 11-12-2003
Difference in LINUX and SOLARIS

Code:
/*
 * one-way-pipe.c  - example of using a pipe to communicate data between a
 *                   process and its child process. The parent reads input
 *                   from the user, and sends it to the child via a pipe.
 *                   The child prints the received data to the screen.
 */

#include <stdio.h>    /* standard I/O routines.                */
#include <unistd.h>   /* defines pipe(), amongst other things. */

/* this routine handles the work of the child process. */
void do_child(int data_pipe[]) {
    int c;	/* data received from the parent. */
    int rc;	/* return status of read().       */

    /* first, close the un-needed write-part of the pipe. */
    close(data_pipe[1]);

    /* now enter a loop of reading data from the pipe, and printing it */
    while ((rc = read(data_pipe[0], &c, 1)) > 0) {
	putchar(c);
    }

    /* probably pipe was broken, or got EOF via the pipe. */
    exit(0);
}

/* this routine handles the work of the parent process. */
void do_parent(int data_pipe[])
{
    int c;	/* data received from the user. */
    int rc;	/* return status of getchar().  */

    /* first, close the un-needed read-part of the pipe. */
    close(data_pipe[0]);

    /* now enter a loop of read user input, and writing it to the pipe. */
    while ((c = getchar()) > 0) {
	/* write the character to the pipe. */
        rc = write(data_pipe[1], &c, 1);
	if (rc == -1) { /* write failed - notify the user and exit */
	    perror("Parent: write");
	    close(data_pipe[1]);
	    exit(1);
        }
    }

    /* probably got EOF from the user. */
    close(data_pipe[1]); /* close the pipe, to let the child know we're done. */
    exit(0);
}

/* and the main function. */
int main(int argc, char* argv[])
{
    int data_pipe[2]; /* an array to store the file descriptors of the pipe. */
    int pid;       /* pid of child process, or 0, as returned via fork.    */
    int rc;        /* stores return values of various routines.            */

    /* first, create a pipe. */
    rc = pipe(data_pipe);
    if (rc == -1) {
	perror("pipe");
	exit(1);
    }

    /* now fork off a child process, and set their handling routines. */
    pid = fork();

    switch (pid) {
	case -1:	/* fork failed. */
	    perror("fork");
	    exit(1);
	case 0:		/* inside child process.  */
	    do_child(data_pipe);
	    /* NOT REACHED */
	default:	/* inside parent process. */
	    do_parent(data_pipe);
	    /* NOT REACHED */
    }

    return 0;	/* NOT REACHED */
}

Does anybody know why it only works on Linux but not Solaris? I really want to know the reason as soon as possible. Thanks.

Last edited by Perderabo; 11-12-2003 at 12:11 PM..
# 2  
Old 11-12-2003
It's not Linux verses Solaris, it's Intel x86 verses Sparc. Your program would work on an Intel x86 running Solaris. The Intel x86 is little endian while the Sparc is big endian.

Code like this:

int c;
read(data_pipe[0], &c, 1);

is garbage. Take another look at the man pages for read and write.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Difference Redhat Linux/RH Enterprise Linux

what is the difference between Redhat Linux and Redhat Enterprise Linux. whereas Redhat linux have Server installation options too. (2 Replies)
Discussion started by: hananabbas
2 Replies

2. UNIX for Dummies Questions & Answers

Difference between UNIX and Linux

hi experts please tell me the real difference between unix and linux at kernel structure (1 Reply)
Discussion started by: linurag
1 Replies

3. Linux

What is the difference between Linux and Windows?

Hi, What is the difference between Linux and Windows? Thanks. (5 Replies)
Discussion started by: billcrosby
5 Replies

4. Linux

Difference between Windows and Linux

Hi, What is the difference between Linux and Windows? Thanks. (1 Reply)
Discussion started by: billcrosby
1 Replies

5. UNIX and Linux Applications

What is the difference between chmod in solaris and chmod in Linux?

i think it is the same in both... Iam i right? (1 Reply)
Discussion started by: sumaiya
1 Replies

6. Solaris

time difference on solaris 10

Hi, in the log file, it shows like this <Sep 4, 2009 1:31:06 PM PDT> <Notice> <WebLogicServer> <BEA-000360> <Server started in RUNNING mode> and i filter this log file to capture the time stamp -1:31:06 PM PDT. Can any one please provide the detail on how to find the difference between... (1 Reply)
Discussion started by: alnhk
1 Replies

7. Solaris

Difference between solaris 9 and 10

Hi..., what is the difference between solaris 9 and 10.what are the major changes happend in sol 10.(including boot) (3 Replies)
Discussion started by: rjay.com
3 Replies

8. UNIX for Dummies Questions & Answers

Difference between sun solaris and linux?

Hi All, Iam curious to know wat are the differences between a sun machine and a linux machine?( In terms of architecture,applications etc) Thanks in advance (3 Replies)
Discussion started by: raz
3 Replies

9. UNIX for Dummies Questions & Answers

difference between unix and linux?

Ok, I'm confused. Can someone answer these (stupid) questions please for me? 1. What is the difference between unix and linux? 2. Is FreeBSD a unix distribution? 3. If not, then what is Unix? I actually gone to Unix.com because I thought this is it's official website where I could download... (1 Reply)
Discussion started by: RellioN
1 Replies

10. UNIX for Dummies Questions & Answers

What's the difference between Unix, Linux, and Solaris?

If anyone can tell me the difference between the three or where I can find more info I would appreciated it. I see alot of companies looking for people with knowledge in Unix but every time I try to find information about it I see Linux instead. Is there a market trend in these operating... (2 Replies)
Discussion started by: ITmommy
2 Replies
Login or Register to Ask a Question