Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-17-2014, 06:50 AM   #1
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 151

Rep: Reputation: 15
Problem with same file rename and pick up with two different processes.

I have two processes.

I am renaming file from /opt/ to /opt/renamedir with one process.

Another process is looking for the files in /opt/renamedir with help of glob() and pick up for processing.

Here my problem is,
Process 2 is tried to pick up the file from /opt/renamedir without proper rename (by process 1) and getting file size as ZERO and at rename getting "No such file directory" error and failed to rename the file at process 1.

Is this possible? Is there reason to behave like this? Please help me to solve this problem.

Nagendra R

Last edited by nagendrar; 07-18-2014 at 01:10 AM.
Old 07-17-2014, 08:29 AM   #2
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Show your code. Also are these on the same filesystem?
Old 07-18-2014, 01:10 AM   #3
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 151

Original Poster
Rep: Reputation: 15
Process1 code:

       // After writing the delta at oldpath, renaming it to newpath

       char newpath[1024];
       strcpy_safe(pattern, 1023, "/opt/test/test.log");

       if(rename(oldpath, newpath))
             printf("Error!Failed to rename from %s to %s Error:%s", oldpath, newpath, strerror(errno));
            //Here getting "No such file or directory" error. Even though file exists
Process 2 code:
        char pattern[1024];
        strcpy_safe(pattern, 1023, "/opt/test/*.log");
        glob_t pglob;
        int ix = 0;
        glob(pattern, GLOB_MARK, NULL, &pglob);
        int nfiles = pglob.gl_pathc;
                while(ix < nfiles)
                        //Here check for file size and delete if it zero
Nagendra R

Last edited by nagendrar; 07-18-2014 at 01:12 AM.


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
[SOLVED] Pick out contents of a file andre3050 Linux - Newbie 16 07-03-2013 05:07 PM
Problem with rename/remove text file YouNoobsDie Programming 1 05-16-2013 05:51 AM
Shell script to get name of file, delete original file, rename blank file chrisgti Linux - General 11 09-15-2012 03:49 AM
how to pick random file name from a list of filenames in a text file. pdklinux79 Linux - Newbie 9 06-20-2008 03:46 PM
I need to pick out the first, last and how many from a file...?!!? vous Programming 3 03-22-2005 02:44 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:46 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration