unix

Python exit codes

☆樱花仙子☆ 提交于 2020-07-05 05:27:46
问题 Where can I find information about meaning of exit codes of "python" process on Unix? For instance, if I do "python thisfiledoesntexist.py", I get exit code 2 Summary: from errno import errorcode print errorcode[2] 回答1: As stated, mostly the error codes come from the executed script and sys.exit() . The example with a non existing file as argument to the interpreter fall in a different category. Though its stated nowhere I would guess, that these exit codes are the "standard" linux error

How to close a file descriptor from another process in unix systems

↘锁芯ラ 提交于 2020-07-04 05:48:51
问题 You can use command lsof to get file descriptors for all running processes, but what I would like to do is to close some of those descriptors without being inside that process. This can be done on Windows, so you can easily unblock some application. Is there any command or function for that? 回答1: In Windows you can use a program to do it because someone wrote a program that inserts a device driver into the running kernel to do it. By the way it can be dangerous to do this, because after you

Event-driven Model in C with Sockets

一曲冷凌霜 提交于 2020-07-04 05:46:51
问题 I am really interested in event-driven programming in C especially with sockets so I am going to dedicate some time doing my researches. Let's assume that I want to build a program with much File and Network I/O like a client/server app, basically, the first question is what is the philosophy behind this model. While in normal programming I would spawn new processes, how come a single process can actually serve many other requests. For example, there are some web-servers which can handle

Event-driven Model in C with Sockets

眉间皱痕 提交于 2020-07-04 05:46:28
问题 I am really interested in event-driven programming in C especially with sockets so I am going to dedicate some time doing my researches. Let's assume that I want to build a program with much File and Network I/O like a client/server app, basically, the first question is what is the philosophy behind this model. While in normal programming I would spawn new processes, how come a single process can actually serve many other requests. For example, there are some web-servers which can handle

Bash Separate values with commas then surround them with quotes in variable

a 夏天 提交于 2020-07-03 13:32:09
问题 I have the below bash script: STR1="US-1234 US-7685 TKT-008953" #STR2= "${STR1// /,}" STR2=`echo $STR1 | sed 's/ /,/g'` echo $STR2 Current output: US-1234,US-7685,TKT-008953 Expected output: 'US-1234','US-9754','TKT-007643' 回答1: With bash and its parameter expansion: STR1="US-1234 US-7685 TKT-008953" STR1="${STR1// /\',\'}" STR1="${STR1/#/\'}" echo "${STR1/%/\'}" Output: 'US-1234','US-7685','TKT-008953' 回答2: You may use STR2="'$(echo "$STR1" | sed "s/ /','/g")'" See online demo All spaces are

Creating a file with open() or creat() has fewer permission bits set than I asked for

随声附和 提交于 2020-07-03 10:01:26
问题 I am writing a program to mimic the cp utility. However, I cannot get the file permissions to work correctly. I know that they are stored in the structure stat and stored in the st_mode field with stat . My issue is that I do not get the write permission for the group or other categories, i.e. I get -rwxr-xr-x as the permissions for the file even though the source file is -rwxrwxrwx . The statement where I set the permissions is below. if ( (dest_fd = open(dest_file, O_WRONLY|O_CREAT, (stats

Resetting password of PostgreSQL on Ubuntu [closed]

丶灬走出姿态 提交于 2020-07-02 03:22:31
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . Improve this question In Ubuntu, I installed PostgreSQL database and created a superuser for the server. If I forgot the password of the postgresql superuser, how can I reset it (the password) for that user? I tried uninstalling it and then installing it again but the previously created superuser is retained.

C utility to print filenames in current directory (Unix)

Deadly 提交于 2020-06-29 11:03:54
问题 Fairly new to C and Unix. I currently have: #include "stdio.h" #include <dirent.h> #include <unistd.h> int main(int argc, char ** argv) { char * current = get_current_dir_name(); //where error occurs DIR * directory = NULL; directory = opendir(current); if(directory == NULL) return -1; struct dirent * ent; while((ent = readdir (directory)) != NULL) printf("%s\n", ent -> d_name); if(closedir(directory) < 0) return -1; } I'm being told: dir.c:15: warning: initialization makes pointer from

Unix - How to convert octal escape sequences via pipe

半世苍凉 提交于 2020-06-29 09:31:39
问题 I'm pulling data from a file (in this case an exim mail log) and often it saves characters in an escaped octal sequence like \NNN where 'N' represents an octal value 0-7. This mainly happens when the subject is written in non-Latin characters (Arabic for example). My goal is to find the cleanest way to convert these octal characters to display correctly in my utf-8 enabled terminal, specifically in 'less' as there is the potential for lots of output. The best approach I have found so far is

SSH session - fixed port on the client side

拟墨画扇 提交于 2020-06-29 08:51:56
问题 Is it possible to set the fixed port on the client side of the connection? I connect to the ssh-server using port 22 and the client socket is getting random port to identify the session. An example (output from netstat -atn) tcp4 0 0 <server>.22 <client>.54117 ESTABLISHED In this example, client gets port 54117. For the test purposes, I'd like a fixed port to be assigned for the client, let's say 40185. So I'd love the following output: tcp4 0 0 <server>.22 <client>.40185 ESTABLISHED Is it