我试图在c中为退出信号创建一个处理程序,我的操作系统是ubuntu.
我正在使用sigaction方法来注册我的自定义处理程序方法.
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
Run Code Online (Sandbox Code Playgroud)
这是我的代码
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void CustomHandler(int signo)
{
printf("Inside custom handler");
switch(signo)
{
case SIGFPE:
printf("ERROR: Illegal arithmatic operation.\n");
break;
}
exit(signo);
}
void newCustomHandler(int signo)
{
printf("Inside new custom handler");
switch(signo)
{
case SIGINT:
printf("ERROR: Illegal arithmatic operation.\n");
break;
}
exit(signo);
}
int main(void)
{
long value;
int i;
struct sigaction act = {CustomHandler};
struct sigaction newact = {newCustomHandler};
newact = act; …
Run Code Online (Sandbox Code Playgroud) 我已经为一个线程创建了一个函数,但我想将多个参数传递给该函数.
这是我的源代码:
#include "work.h"
#include <stdio.h>
#include <unistd.h>
#include <pthread.h> // compile with -lpthread
int count = 20;
void* ChildProc(void* arg)
{
int i;
for(i = 1; i <= count; i++)
{
printf("%s:%d from thread <%x>\n", arg, i, pthread_self());
DoWork(i);
}
return NULL;
}
void ParentProc(void)
{
int i;
for(i = count / 2; i > 0; i--)
{
printf("Parent:%d from thread <%x>\n", i, pthread_self());
DoWork(i);
}
}
int main(void)
{
pthread_t child;
pthread_create(&child, NULL, ChildProc, "Child");
ParentProc();
pthread_join(child, NULL); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试e:\test
使用ReadDirectoryChangesW API 监视目录.
我的代码:
#define UNICODE
#define WIN32_WINNT 0x0500
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
HANDLE hDir;
int _tmain(int argc, _TCHAR* argv[])
{
FILE_NOTIFY_INFORMATION fniDir;
DWORD i = 0;
hDir = CreateFile(_T("e:\\test"), GENERIC_READ , FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
ReadDirectoryChangesW(hDir, &fniDir, sizeof(fniDir), TRUE, FILE_NOTIFY_CHANGE_FILE_NAME, &i, NULL, NULL);
while(TRUE)
{
if(i>0)
wprintf(L"%s", fniDir.FileName);
}
CloseHandle(hDir);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不知道我的代码有什么问题,因为我还没有完全理解ReadDirectoryChangesW文档,特别是LPOVERLAPPED
参数.
当我运行代码时,我没有得到任何输出,除了一个空白的控制台窗口.有人能指出我正确的方向吗?
谢谢.
c winapi filenames readdirectorychangesw systems-programming
我是汇编语言的新手.我编写了一个程序,用于获取输入,然后显示该数字是否为素数.
这是我的源代码.
.intel_syntax noprefix
.include "console.i"
.data
Num: .long 0
.text
ask: .asciz "Enter a +ve number : "
ansp: .asciz " is prime."
ans: .asciz " is not prime."
_entry:
Prompt ask
GetInt Num
mov eax,Num # store Number in eax
#mov ecx,0 # Reset ecx to 0
mov ecx,0 # Reset ecx t0 2 for dividing.
cdq
1: inc ecx # increment ecx
mov ebx,eax #backup eax
Div ecx #Divide eax by ecx
cmp edx,0 #if remainder is …
Run Code Online (Sandbox Code Playgroud) 我对这个程序感到困惑.
#include <stdio.h>
int main(void)
{
int value = 10;
char ch = 'A';
int* ptrValue = &value;
char* ptrCh = &ch;
int* ptrValue1 = value;
char* ptrCh1 = ch;
printf("Value of ptrValue = %d and value of ptrValue1 = %d\n", *ptrValue, ptrValue1);
printf("Value of ptrCh = %c and value of ptrCh1 = %c\n", *ptrCh, *ptrCh1);
}
Run Code Online (Sandbox Code Playgroud)
编译这个程序时我收到两个警告
unipro @ ubuguest:/ SoftDev/ADSD/Module 1/Unit 1/Rd/C/System $ cc charPointers.c -o charPointers
charPointers.c:在函数'main'中:
charPointers.c:11:警告:初始化使指针来自没有
强制转换的整数charPointers.c:12:警告:初始化使得整数指针没有强制转换
我知道他们的意思.
在运行程序时,我收到以下错误.
unipro @ ubuguest:/ SoftDev/ADSD/Module 1/Unit 1/Rd/C/System …
我有一个名为 的 servlet 文件NewServlet.java
。我的 AJAX 脚本调用此 servlet 来检索响应。
我已经通过在浏览器中测试 servlet 来验证它。
但是当我从我的 AJAX 脚本中调用它时,它给了我一个空白responseText
和一个错误,上面写着
XMLHttpRequest 无法加载 http://localhost:8084/WebApplication1/NewServlet。Access-Control-Allow-Origin 不允许 Origin null
NewServlet.java
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<option value='1'>one</option>");
out.println("<option value='2'>two</option>");
out.println("<option value='3'>three</option>");
out.println("<option value='4'>four</option>");
out.println("<option value='5'>five</option>");
out.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
} …
Run Code Online (Sandbox Code Playgroud) 我面临一个奇怪的问题:
我正在加密cookie的内容.
当我在Visual Studio中运行它时,我的代码工作正常,但给我一个"错误的请求,HTTP错误400.请求形成错误." 当我从服务器运行它.
以下是加密类Cookqs的加密类,位于app_code中:
public class EncryptCook
{
public EncryptCook()
{
//
// TODO: Add constructor logic here
//
}
public string EncryptString(string data)
{
try
{
string encryptString = "";
if (data != "")
{
char a;
int key = Convert.ToInt16(DateTime.Now.Day);
int j = 0;
for (int i = 0; i < data.Length; i++)
{
j = (int)data[i];
j = j + key;
a = (char)j;
encryptString = encryptString + Convert.ToString(a);
}
}
return encryptString;
}
catch …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的程序中实现EINVAL,EPERM,ESRCH.
ERRORS
EINVAL指定了无效信号.
EPERM该过程无权将信号发送到任何目标进程.ESRCH pid或进程组不存在.
这是我的源代码:
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
int main(void)
{
int errno, pid;
puts("Enter a process id : ");
scanf("%d", &pid);
errno = kill(pid, 1);
if(errno == -1)
{
printf("Cannot find or kill the specified process\n");
}
switch(errno)
{
case EINVAL:
printf("An invalid signal was specified.\n");
break;
case EPERM:
printf("The process does not have permission to send the signal to any of the target processes.\n");
break;
case ESRCH:
printf("The pid or process group …
Run Code Online (Sandbox Code Playgroud) 如果在C#中的DateTime类型上使用增量运算符(++)会发生什么?
例如,如果我这样做:
DateTime blah = new DateTime(2010, 12, 24);
blah++;
Run Code Online (Sandbox Code Playgroud)
什么会变成什么?这会增加一个刻度还是一天?
或者这甚至是合法的?
我周围没有开发环境,也不会有几天,或者我会试着找出来.我太好奇不能等待,所以我想我会问社区.
我的一位同事建议我使用WebRequest.Create实际向指定的URL发送Web请求,我不必使用异步Web请求以避免等待.
这是真的?
我怎么不同意他,当我向他展示文档但他说他一直在调用WebRequest.Create发送请求.
我不确定这是否属实,因为我对.net没有深入的了解