Community
cancel
Showing results for 
Search instead for 
Did you mean: 
ye_f_1
Beginner
63 Views

Cat not open file on Phi

This is my program,it is very simple.

 1 #include <stdio.h>
  2 #include <fcntl.h>
  3 #include <unistd.h>
  4
  5 int
  6 main(){
  7
  8         int fd;
  9         fd=open("./p",O_RDWR);
 10         if(fd<0)
 11                 printf("+++++\n");
 12         close(fd);
 13         
 14         return 0;
 15 }

I compile it .   icc open.c -o open -mmic

Then I forward it to phi.  scp open mic0:/home/wj/test/data/soc

when I ssh to phi and run it on Phi, it work fine.

But when I input command on CPU(host) in order to running it on Phi,it is failed and get "+++++".   ssh -x mic0 /home/wj/test/data/soc/open

I seems that the program can open file in later way.I don not install OFED(my host system is Ubuntu),Is it related to this problem?

In addition to,I find when I ssh to Phi,I cat get following information.

Tunnel device open failed.
Could not request tunnel forwarding

What's wrong?

0 Kudos
2 Replies
JJK
New Contributor III
63 Views

when you run "ssh mic0 <some command>" the current working directory is set to the remote home directory. Try running

ssh mic0 /bin/pwd

for example. An "open(..., A_RDWR)" will fail if the file does not exist. Try the following code:

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

int
main(){
    int fd;
    char curdir[1000];

    printf("cwd = %s\n", getcwd( curdir, sizeof(curdir)));

    fd=open("./p",O_RDWR);
    if(fd<0) printf("+++++\n");

    printf("errno = %d (%s)\n", errno, strerror(errno));
    close(fd);
    return 0;
}

 

Loc_N_Intel
Employee
63 Views

Hello,

As JJK points out, the default directory on mic is not where you placed your mic binary. In order to execute your binary (I assume you placed both "open" and "p" under /tmp), you may want to go to that directory and run the program from there. Note that you can combine two commands with a semicolon  ";" . For example, please try the following command from host:

# ssh mic0 "cd /tmp; ./open" 

Reply