Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:32:20+00:00 2026-06-12T06:32:20+00:00

#include<apue.h> #include<unistd.h> #include<fcntl.h> #include<string.h> int main(int argc , char *argv[]) { int fd =

  • 0
#include<apue.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>

int main(int argc , char *argv[])
{
    int fd = open("test.txt",O_WRONLY | O_CREAT | O_TRUNC);
    int pid,status;
    const char *str_for_parent = "str_for_parent\n";
    const char *str_for_child = "str_for_child\n";
    if ((pid = fork()) < 0)
        err_sys("fork error");
    else if (pid == 0)
    {
        write(fd,str_for_child,strlen(str_for_child)+1);
        _exit(0);
    }
    wait(&status);
    write(fd,str_for_parent,strlen(str_for_parent)+1);

    return 0;
}

The test.txt is created by open().But it’s permission(---------x) is different with those files(-rw-rw-r--) created by touch or any other softwares in my system.my umask is 0002

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:32:21+00:00Added an answer on June 12, 2026 at 6:32 am

    open actually takes an (optional) third parameter:

    int open(const char *pathname, int flags, mode_t mode);
    

    The mode of the new file is set to the AND of mode and the inverse of your umask (ie, mode & ~umask). Since you’re not passing mode, it’s getting initialized to some garbage, and you’re getting the wrong mode as a result.

    Generally if you’re passing O_CREAT, you should pass a mode of 0666, unless you have some specific reason to use some other mode (eg, if you want to make sure the file is not readable by other users regardless of what the umask is set to).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main (int argc, const char * argv[])
#include <QtCore/QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); a.setApplicationName(xxx); char bb[25]
#include<QApplication> #include<QTranslator> #include<QObject> #include<QTextCodec> #include<QWidget> int main(int argc, char* argv[]) { QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale()); QApplication app(argc,
#include <stdio.h> #include <stdlib.h> int main(int argc,char *argv[]) { system(PAUSE); return 0; } After
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, char * argv[]) { /*
#include <iostream> using namespace std; int main(int argc, const char * argv[]) { int
#include <GL/gl.h> #include <GL/glut.h> void display(); void init(); int main(int argc, char* argv[]) {
#include framecapture.h #include <iostream> #include <QtWidget> int main(int argc, char * argv[]) { if
#include <stdio.h> #include stdlib.h int main(int argc, const char * argv[]) { int i,j;
#include <iostream> #include <fstream> using namespace std; int main() { ifstream stream1(source.txt); string line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.